def test_adaptive_scale_main(): r""" CommandLine: python -m pyhesaff.tests.test_adaptive_scale --test-test_adaptive_scale_main python -m pyhesaff.tests.test_adaptive_scale --test-test_adaptive_scale_main --show Example: >>> # DISABLE_DOCTEST >>> from pyhesaff.tests.test_adaptive_scale import * # NOQA >>> # build test data >>> # execute function >>> result = test_adaptive_scale_main() >>> # verify results >>> print(result) """ from plottool import draw_func2 as df2 from plottool.viz_keypoints import show_keypoints import vtool.ellipse as vtellipse print('__main__ = test_adaptive_scale.py') np.set_printoptions(threshold=5000, linewidth=5000, precision=3) #adaptive_locals = test_adaptive_scale() # They seem to work # TODO: take the gui functions out of this test test_adaptive_scale() if ut.show_was_requested(): exec(df2.present())
def test_pyheaff(img_fpath): r""" This show is interactive in this test! Args: img_fpath (str): CommandLine: python -m pyhesaff.tests.test_pyhesaff --test-test_pyheaff python -m pyhesaff.tests.test_pyhesaff --test-test_pyheaff --show Example: >>> # ENABLE_DOCTEST >>> from pyhesaff.tests.test_pyhesaff import * # NOQA >>> img_fpath = ut.grab_test_imgpath('jeff.png') >>> test_pyheaff(img_fpath) >>> ut.show_if_requested() """ import pyhesaff kpts, desc = pyhesaff.detect_feats(img_fpath) rchip = cv2.imread(img_fpath) if ut.show_was_requested(): from plottool.interact_keypoints import ishow_keypoints ishow_keypoints(rchip, kpts, desc) return locals()
def TEST_QUERY(ibs): r""" CommandLine: python -m ibeis.tests.test_ibs_query --test-TEST_QUERY python -m ibeis.tests.test_ibs_query --test-TEST_QUERY --show Example: >>> # ENABLE_DOCTEST >>> from ibeis.tests.test_ibs_query import * # NOQA >>> import plottool as pt >>> import ibeis >>> ibs = ibeis.opendb('testdb1') >>> TEST_QUERY(ibs) >>> pt.show_if_requested() """ print('[TEST_QUERY]') daid_list = ibs.get_valid_aids() print('[TEST_QUERY] len(daid_list)=%r' % (len(daid_list))) qaid_list = daid_list[0:1] print('[TEST_QUERY] len(qaid_list)=%r' % (len(qaid_list))) qres_list = ibs.query_chips(qaid_list, daid_list, use_cache=False, use_bigcache=False) qres_list_ = ibs.query_chips(qaid_list, daid_list) try: vals1 = qres_list vals2 = qres_list_ assert len(vals1) == 1, 'expected 1 qres in result' assert len(vals2) == 1, 'expected 1 qres in result' #assert list(qres_dict.keys()) == list(qres_dict_.keys()), 'qres cache doesnt work. key error' qres1 = vals1[0] qres2 = vals2[0] inspect_str1 = qres1.get_inspect_str(ibs) inspect_str2 = qres2.get_inspect_str(ibs) print(inspect_str1) assert inspect_str1 == inspect_str2, 'qres cache inconsistency' assert vals1 == vals2, 'qres cache doesnt work. val error' except AssertionError as ex: utool.printex(ex, key_list=list(locals().keys())) raise if ut.show_was_requested(): for qres in qres_list: top_aids = qres.get_top_aids() #top_aids = utool.safe_slice(top_aids, 3) aid2 = top_aids[0] fnum = df2.next_fnum() df2.figure(fnum=fnum, doclf=True) qres.ishow_top(ibs, fnum=fnum, top_aids=top_aids, ensure=False, annot_mode=1) df2.set_figtitle('Query Result') df2.adjust_subplots_safe(top=.8) return locals()
def after(self, errors=[]): """ Delays error reporting until after visualization prints errors, then shows you the graph, then finally if any errors were discovered they are raised """ errors = errors + self._errors if errors: ut.cprint('PRINTING %d FAILURE' % (len(errors)), 'red') for msg in errors: logger.info(msg) ut.cprint('HAD %d FAILURE' % (len(errors)), 'red') if ut.show_was_requested(): pt.all_figures_tile(percent_w=0.5) ut.show_if_requested() if errors: raise AssertionError('There were errors')
def simple_iterative_test(): r""" CommandLine: python -m pyhesaff.tests.test_pyhesaff_simple_iterative --test-simple_iterative_test python -m pyhesaff.tests.test_pyhesaff_simple_iterative --test-simple_iterative_test --show Example: >>> # GUI_DOCTEST >>> from pyhesaff.tests.test_pyhesaff_simple_iterative import * # NOQA >>> result = simple_iterative_test() >>> print(result) >>> ut.show_if_requested() """ import pyhesaff fpath_list = [ ut.grab_test_imgpath('lena.png'), ut.grab_test_imgpath('carl.jpg'), ut.grab_test_imgpath('grace.jpg'), ut.grab_test_imgpath('ada.jpg'), ] kpts_list = [] for img_fpath in fpath_list: kpts, vecs = pyhesaff.detect_feats(img_fpath) print('img_fpath=%r' % img_fpath) print('kpts=%s' % (ut.truncate_str(repr(kpts)), )) print('vecs=%s' % (ut.truncate_str(repr(vecs)), )) assert len(kpts) == len(vecs) assert len(kpts) > 0, 'no keypoints were detected!' kpts_list.append(kpts) if ut.show_was_requested(): import matplotlib as mpl from matplotlib import pyplot as plt fig = plt.figure() for i, fpath, kpts in enumerate(zip(fpath_list, kpts_list), start=1): ax = fig.add_subplot(2, 2, i) img = mpl.image.imread(fpath) plt.imshow(img) _xs, _ys = kpts.T[0:2] ax.plot(_xs, _ys, 'ro', alpha=.5)
def fix_pz_master(): r""" CommandLine: python -m ibeis.algo.hots.devcases --test-fix_pz_master --show Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.devcases import * # NOQA >>> # build test data >>> # execute function >>> result = fix_pz_master() >>> # verify results >>> print(result) """ # ReROI aid4513+name """ 82 97 117 118 157 213 299 336 351 368 392 415 430 434 441 629 664 679 682 685 695 835 1309 1317 1327 1382 1455 1816 3550 4067 4125 4131 4141 4191 4239 4242 4256 4257 4258 4439 4489 4625 4797 4800 4809 4812 4813 4819 4829 4831 4864 4865 4871 4877 4879 4885 4886 4891 4897 4899 4902 4904 4909 4912 4931 4933 4934 4935 4936 4952 5053 5073 5248 5249 5367 5776 5999 6150 6699 6882 7197 7225 7231 7237 7247 7254 7263 7280 7298 7357 7373 7385 7412 7424 7426 7464 7470 7472 7473 7479 7480 7507 7533 7535 7537 7578 7589 7629 7666 7669 7672 7720 7722 7734 7740 7754 7778 7792 7796 7798 7807 7812 7813 7829 7840 7846 7875 7876 7888 7889 7896 7899 7900 7901 7908 7909 7911 7915 7916 7917 7925 7931 7936 7938 7944 7947 7951 7954 7961 7965 7966 7978 7979 7981 7988 7992 7998 8019 8044 8045 8047 8051 8052 8059 8062 8063 8064 8066 8069 8074 8075 8083 8088 8093 8094 8095 8100 8102 8103 8105 8113 8116 8118 8119 8120 8123 8126 8128 8139 8144 8151 8152 8153 8154 8155 8157 8165 8170 8178 8180 8186 8188 8189 8195 8197 8198 8201 8202 8206 8213 8216 8226 8228 8231 8238 8245 8258 8265 8269 8276 8281 8285 8287 8297 8301 8305 8306 8308 8312 8318 8319 8321 8329 8332 8345 8349 8357 8361 8365 8367 8372 8373 8381 8386 8389 8392 8398 8399 8400 8402 8403 8406 8407 8412 8423 8424 8426 8427 8428 8429 8431 8439 8444 8446 8447 8450 8456 8457 8461 8463 8464 8466 8471 8472 8477 8481 8486 8489 8490 8494 8497 8499 8500 8501 8503 8506 8508 8535 8536 8537 8538 8539 8540 8541 8544 8545 8550 8552 8554 8555 8557 8558 8559 8564 8567 8568 8574 8575 8582 8584 8587 8589 8591 8592 8593 8596 8597 8601 8602 8605 8607 8608 8616 8617 8618 8619 8620 8621 8622 8629 8637 8639 8647 8662 8664 8665 8666 8673 8674 8676 8689 8691 8692 8693 8694 8699 8700 8702 8703 8712 8714 8715 8719 8724 8733 8734 8736 """ qaids_str = """ 82 117 118 213 299 336 351 368 392 430 434 441 495 616 629 664 679 682 685 695 835 915 1317 1382 3550 4239 4242 4246 4256 4257 4258 4439 4445 4447 4489 4706 4800 4812 4813 4819 4828 4829 4831 4864 4865 4871 4877 4879 4885 4886 4891 4897 4899 4902 4904 4909 4912 4933 4934 4936 4952 5053 5073 5248 5367 5776 7197 7225 7254 7263 7298 7309 7470 7473 7479 7507 7535 7570 7589 7666 7672 7722 7734 7740 7754 7760 7796 7798 7807 7813 7829 7840 7875 7876 7888 7889 7896 7899 7900 7901 7908 7909 7911 7916 7917 7925 7931 7934 7936 7938 7944 7947 7951 7954 7961 7964 7965 7966 7978 7979 7981 7988 7992 7998 8019 8044 8045 8047 8051 8052 8058 8059 8062 8063 8064 8066 8074 8075 8083 8088 8094 8095 8100 8101 8102 8103 8105 8111 8113 8116 8119 8120 8121 8123 8126 8128 8144 8151 8152 8153 8155 8156 8157 8165 8170 8180 8186 8188 8198 8201 8206 8213 8216 8226 8228 8231 8238 8258 8276 8281 8285 8287 8295 8297 8301 8305 8306 8308 8312 8318 8319 8329 8332 8355 8357 8361 8365 8367 8372 8373 8381 8386 8388 8389 8392 8398 8399 8402 8403 8406 8407 8412 8424 8425 8426 8428 8429 8439 8442 8444 8446 8447 8449 8450 8452 8456 8457 8461 8463 8464 8466 8470 8471 8481 8486 8489 8490 8494 8497 8499 8500 8501 8503 8506 8508 8535 8536 8537 8538 8539 8540 8544 8545 8550 8554 8555 8557 8558 8559 8563 8564 8567 8574 8575 8582 8584 8587 8589 8592 8593 8596 8597 8600 8601 8604 8605 8607 8608 8616 8617 8618 8619 8620 8621 8622 8623 8629 8637 8639 8647 8662 8665 8666 8673 8674 8676 8691 8693 8694 8699 8700 8702 8703 8712 8714 8715 8719 8724 8731 8733 8734 8736 """ qaids_ = map(int, filter(len, qaids_str.replace('\n', ' ').split(' '))) import ibeis ibeis._preload() from ibeis.gui import inspect_gui import guitool ibs = ibeis.opendb('PZ_Master0') #ibs._default_config() #ibs.cfg.save() daids = ibs.get_valid_aids(minqual='poor') qaids = ibs.filter_junk_annotations(qaids_) #qaids = qaids[64:128] qreq_ = ibs.new_query_request(qaids, daids) #qreq_.lazy_load() qres_list = ibs.query_chips(qreq_=qreq_, verbose=True) qres_wgt = inspect_gui.launch_review_matches_interface( ibs, qres_list, dodraw=ut.show_was_requested()) if ut.show_was_requested(): guitool.guitool_main.qtapp_loop() return qres_wgt
def test_sver_wrapper(): """ Test to ensure cpp and python agree and that cpp is faster CommandLine: python -m vtool.sver_c_wrapper --test-test_sver_wrapper python -m vtool.sver_c_wrapper --test-test_sver_wrapper --rebuild-sver python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --dummy python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --fname1=easy1.png --fname2=easy2.png python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --fname1=easy1.png --fname2=hard3.png python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --fname1=carl.jpg --fname2=hard3.png Example: >>> # ENABLE_DOCTEST >>> from vtool.sver_c_wrapper import * # NOQA >>> test_sver_wrapper() Ignore: %timeit call_python_version(*args) %timeit get_affine_inliers_cpp(*args) """ import vtool.spatial_verification as sver import vtool.tests.dummy as dummy xy_thresh_sqrd = ktool.KPTS_DTYPE(.4) scale_thresh_sqrd = ktool.KPTS_DTYPE(2.0) ori_thresh = ktool.KPTS_DTYPE(TAU / 4.0) keys = 'xy_thresh_sqrd, scale_thresh_sqrd, ori_thresh'.split(', ') print(ut.dict_str(ut.dict_subset(locals(), keys))) def report_errors(): pass if ut.get_argflag('--dummy'): testtup = dummy.testdata_dummy_matches() (kpts1, kpts2, fm_input, fs_input, rchip1, rchip2) = testtup fm_input = fm_input.astype(fm_dtype) #fm_input = fm_input[0:10].astype(fm_dtype) #fs_input = fs_input[0:10].astype(np.float32) else: fname1 = ut.get_argval('--fname1', type_=str, default='easy1.png') fname2 = ut.get_argval('--fname2', type_=str, default='easy2.png') testtup = dummy.testdata_ratio_matches(fname1, fname2) (kpts1, kpts2, fm_input, fs_input, rchip1, rchip2) = testtup # pack up call to aff hypothesis import vtool as vt import scipy.stats.mstats scales1 = vt.get_scales(kpts1.take(fm_input.T[0], axis=0)) scales2 = vt.get_scales(kpts2.take(fm_input.T[1], axis=0)) #fs_input = 1 / scipy.stats.mstats.gmean(np.vstack((scales1, scales2))) fs_input = scipy.stats.mstats.gmean(np.vstack((scales1, scales2))) print('fs_input = ' + ut.numpy_str(fs_input)) #fs_input[0:-9] = 0 #fs_input = np.ones(len(fm_input), dtype=fs_dtype) #ut.embed() #fs_input = scales1 * scales2 args = (kpts1, kpts2, fm_input, fs_input, xy_thresh_sqrd, scale_thresh_sqrd, ori_thresh) ex_list = [] try: with ut.Indenter('[TEST1] '): inlier_tup = vt.compare_implementations( sver.get_affine_inliers, get_affine_inliers_cpp, args, lbl1='py', lbl2='c', output_lbl=('aff_inliers_list', 'aff_errors_list', 'Aff_mats') ) out_inliers, out_errors, out_mats = inlier_tup except AssertionError as ex: ex_list.append(ex) raise try: import functools with ut.Indenter('[TEST2] '): bestinlier_tup = vt.compare_implementations( functools.partial(sver.get_best_affine_inliers, forcepy=True), get_best_affine_inliers_cpp, args, show_output=True, lbl1='py', lbl2='c', output_lbl=('bestinliers', 'besterror', 'bestmat') ) bestinliers, besterror, bestmat = bestinlier_tup except AssertionError as ex: ex_list.append(ex) raise if len(ex_list) > 0: raise AssertionError('some tests failed. see previous stdout') #num_inliers_list = np.array(map(len, out_inliers_c)) #best_argx = num_inliers_list.argmax() ##best_inliers_py = out_inliers_py[best_argx] #best_inliers_c = out_inliers_c[best_argx] if ut.show_was_requested(): import plottool as pt fm_output = fm_input.take(bestinliers, axis=0) fnum = pt.next_fnum() pt.figure(fnum=fnum, doclf=True, docla=True) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm_input, ell_linewidth=5, fnum=fnum, pnum=(2, 1, 1)) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm_output, ell_linewidth=5, fnum=fnum, pnum=(2, 1, 2)) pt.show_if_requested()
def test_cpp_rotinvar_main(): r""" CommandLine: python -m pyhesaff.tests.test_cpp_rotation_invariance --test-test_cpp_rotinvar_main python -m pyhesaff.tests.test_cpp_rotation_invariance --test-test_cpp_rotinvar_main --show Example: >>> # DISABLE_DOCTEST >>> from pyhesaff.tests.test_cpp_rotation_invariance import * # NOQA >>> # build test data >>> # execute function >>> result = test_cpp_rotinvar_main() >>> # verify results >>> print(result) """ # TODO; take visualization out of this test by default from pyhesaff.tests import pyhestest import pyhesaff # Read data print('[rotinvar] loading test data') img_fpath = pyhestest.get_test_image() [kpts1], [desc1] = pyhesaff.detect_feats_list([img_fpath], rotation_invariance=False) [kpts2], [desc2] = pyhesaff.detect_feats_list([img_fpath], rotation_invariance=True) np.set_printoptions(threshold=5000, linewidth=5000, precision=8, suppress=True) print('kpts1.shape = %r' % (kpts1.shape, )) print('kpts2.shape = %r' % (kpts2.shape, )) print('desc1.shape = %r' % (desc1.shape, )) print('desc2.shape = %r' % (desc2.shape, )) print('\n----\n'.join([ str(k1) + '\n' + str(k2) for k1, k2 in zip(kpts1[0:10], kpts2[0:10]) ])) n = 4 #clip = min(len(kpts1), n) # HACK FIXME fxs = np.array(pyhestest.spaced_elements2(kpts2, n).tolist()[0:3]) print('fxs=%r' % fxs) kpts1 = kpts1[fxs] kpts2 = kpts2[fxs] desc1 = desc1[fxs] desc2 = desc2[fxs] print('\n----\n'.join( [str(k1) + '\n' + str(k2) for k1, k2 in zip(kpts1, kpts2)])) imgBGR = pyhestest.cv2.imread(img_fpath) sel = min(len(kpts1) - 1, 3) TEST_keypoint(imgBGR, img_fpath, kpts1, desc1, sel, fnum=1, figtitle='Downward Rotation') TEST_keypoint(imgBGR, img_fpath, kpts2, desc2, sel, fnum=9001, figtitle='Adapted Rotation') #locals_ = TEST_keypoint(imgBGR, img_fpath, kpts1, desc1, sel) #exec(utool.execstr_dict(locals_, 'locals_')) #exec(utool.execstr_dict(f1_loc, 'f1_loc')) # NOQA #pinteract.interact_keypoints(imgBGR, kpts2, desc, arrow=True, rect=True) if ut.show_was_requested(): exec(df2.present())
def fourier_devtest(img): r""" Args: img (ndarray[uint8_t, ndim=2]): image data CommandLine: python -m vtool.quality_classifier --test-fourier_devtest --show References: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_transforms/py_fourier_transform/py_fourier_transform.html http://cns-alumni.bu.edu/~slehar/fourier/fourier.html Example: >>> # DISABLE_DOCTEST >>> from vtool.quality_classifier import * # NOQA >>> import vtool as vt >>> # build test data >>> img_fpath = ut.grab_test_imgpath('lena.png') >>> img = vt.imread(img_fpath, grayscale=True) >>> # execute function >>> magnitude_spectrum = fourier_devtest(img) """ import plottool as pt def pad_img(img): rows, cols = img.shape nrows = cv2.getOptimalDFTSize(rows) ncols = cv2.getOptimalDFTSize(cols) right = ncols - cols bottom = nrows - rows bordertype = cv2.BORDER_CONSTANT nimg = cv2.copyMakeBorder(img, 0, bottom, 0, right, bordertype, value=0) return nimg def convert_to_fdomain(img): dft = cv2.dft(img.astype(np.float32), flags=cv2.DFT_COMPLEX_OUTPUT) #dft_shift = np.fft.fftshift(dft) return dft def convert_from_fdomain(dft): img = cv2.idft(dft) img = cv2.magnitude(img[:, :, 0], img[:, :, 1]) img /= img.max() return img * 255.0 def get_fdomain_mag(dft_shift): magnitude_spectrum = np.log(cv2.magnitude(dft_shift[:, :, 0], dft_shift[:, :, 1])) return magnitude_spectrum def imgstats(img): print('stats:') print(' dtype = %r ' % (img.dtype,)) print(' ' + ut.get_stats_str(img, axis=None)) nimg = pad_img(img) dft = convert_to_fdomain(nimg) #freq_domain = np.fft.fft2(img) #freq_domain_shift = np.fft.fftshift(freq_domain) rows, cols = nimg.shape crow, ccol = rows / 2 , cols / 2 # create a mask first, center square is 1, remaining all zeros mask = np.zeros((rows, cols, 2), np.uint8) mask[crow - 30:crow + 30, ccol - 30:ccol + 30] = 1 dft_mask = np.fft.ifftshift(np.fft.fftshift(dft) * mask) img_back = convert_from_fdomain(dft_mask) imgstats(dft) imgstats(mask) imgstats(nimg) imgstats(nimg) print('nimg.shape = %r' % (nimg.shape,)) print('dft_shift.shape = %r' % (dft.shape,)) if ut.show_was_requested(): #import plottool as pt next_pnum = pt.make_pnum_nextgen(nRows=3, nCols=2) pt.imshow(nimg, pnum=next_pnum(), title='nimg') pt.imshow(20 * get_fdomain_mag(dft), pnum=next_pnum(), title='mag(f)') pt.imshow(20 * get_fdomain_mag(dft_mask), pnum=next_pnum(), title='dft_mask') pt.imshow(img_back, pnum=next_pnum(), title='img_back') pt.show_if_requested()
def test_sver_wrapper(): """ Test to ensure cpp and python agree and that cpp is faster CommandLine: python -m vtool.sver_c_wrapper --test-test_sver_wrapper python -m vtool.sver_c_wrapper --test-test_sver_wrapper --rebuild-sver python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --dummy python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --fname1=easy1.png --fname2=easy2.png python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --fname1=easy1.png --fname2=hard3.png python -m vtool.sver_c_wrapper --test-test_sver_wrapper --show --fname1=carl.jpg --fname2=hard3.png Example: >>> # ENABLE_DOCTEST >>> from vtool.sver_c_wrapper import * # NOQA >>> test_sver_wrapper() Ignore: %timeit call_python_version(*args) %timeit get_affine_inliers_cpp(*args) """ import vtool.spatial_verification as sver import vtool.tests.dummy as dummy xy_thresh_sqrd = ktool.KPTS_DTYPE(.4) scale_thresh_sqrd = ktool.KPTS_DTYPE(2.0) ori_thresh = ktool.KPTS_DTYPE(TAU / 4.0) keys = 'xy_thresh_sqrd, scale_thresh_sqrd, ori_thresh'.split(', ') print(ut.dict_str(ut.dict_subset(locals(), keys))) def report_errors(): pass if ut.get_argflag('--dummy'): testtup = dummy.testdata_dummy_matches() (kpts1, kpts2, fm_input, fs_input, rchip1, rchip2) = testtup fm_input = fm_input.astype(fm_dtype) #fm_input = fm_input[0:10].astype(fm_dtype) #fs_input = fs_input[0:10].astype(np.float32) else: fname1 = ut.get_argval('--fname1', type_=str, default='easy1.png') fname2 = ut.get_argval('--fname2', type_=str, default='easy2.png') testtup = dummy.testdata_ratio_matches(fname1, fname2) (kpts1, kpts2, fm_input, fs_input, rchip1, rchip2) = testtup # pack up call to aff hypothesis import vtool as vt import scipy.stats.mstats scales1 = vt.get_scales(kpts1.take(fm_input.T[0], axis=0)) scales2 = vt.get_scales(kpts2.take(fm_input.T[1], axis=0)) #fs_input = 1 / scipy.stats.mstats.gmean(np.vstack((scales1, scales2))) fs_input = scipy.stats.mstats.gmean(np.vstack((scales1, scales2))) print('fs_input = ' + ut.numpy_str(fs_input)) #fs_input[0:-9] = 0 #fs_input = np.ones(len(fm_input), dtype=fs_dtype) #ut.embed() #fs_input = scales1 * scales2 args = (kpts1, kpts2, fm_input, fs_input, xy_thresh_sqrd, scale_thresh_sqrd, ori_thresh) ex_list = [] try: with ut.Indenter('[TEST1] '): inlier_tup = vt.compare_implementations( sver.get_affine_inliers, get_affine_inliers_cpp, args, lbl1='py', lbl2='c', output_lbl=('aff_inliers_list', 'aff_errors_list', 'Aff_mats')) out_inliers, out_errors, out_mats = inlier_tup except AssertionError as ex: ex_list.append(ex) raise try: import functools with ut.Indenter('[TEST2] '): bestinlier_tup = vt.compare_implementations( functools.partial(sver.get_best_affine_inliers, forcepy=True), get_best_affine_inliers_cpp, args, show_output=True, lbl1='py', lbl2='c', output_lbl=('bestinliers', 'besterror', 'bestmat')) bestinliers, besterror, bestmat = bestinlier_tup except AssertionError as ex: ex_list.append(ex) raise if len(ex_list) > 0: raise AssertionError('some tests failed. see previous stdout') #num_inliers_list = np.array(map(len, out_inliers_c)) #best_argx = num_inliers_list.argmax() ##best_inliers_py = out_inliers_py[best_argx] #best_inliers_c = out_inliers_c[best_argx] if ut.show_was_requested(): import plottool as pt fm_output = fm_input.take(bestinliers, axis=0) fnum = pt.next_fnum() pt.figure(fnum=fnum, doclf=True, docla=True) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm_input, ell_linewidth=5, fnum=fnum, pnum=(2, 1, 1)) pt.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm_output, ell_linewidth=5, fnum=fnum, pnum=(2, 1, 2)) pt.show_if_requested()
def test_cpp_rotinvar_main(): r""" CommandLine: python -m pyhesaff.tests.test_cpp_rotation_invariance --test-test_cpp_rotinvar_main python -m pyhesaff.tests.test_cpp_rotation_invariance --test-test_cpp_rotinvar_main --show Example: >>> # DISABLE_DOCTEST >>> from pyhesaff.tests.test_cpp_rotation_invariance import * # NOQA >>> # build test data >>> # execute function >>> result = test_cpp_rotinvar_main() >>> # verify results >>> print(result) """ # TODO; take visualization out of this test by default from pyhesaff.tests import pyhestest import pyhesaff # Read data print('[rotinvar] loading test data') img_fpath = pyhestest.get_test_image() [kpts1], [desc1] = pyhesaff.detect_feats_list([img_fpath], rotation_invariance=False) [kpts2], [desc2] = pyhesaff.detect_feats_list([img_fpath], rotation_invariance=True) np.set_printoptions(threshold=5000, linewidth=5000, precision=8, suppress=True) print('kpts1.shape = %r' % (kpts1.shape,)) print('kpts2.shape = %r' % (kpts2.shape,)) print('desc1.shape = %r' % (desc1.shape,)) print('desc2.shape = %r' % (desc2.shape,)) print('\n----\n'.join([str(k1) + '\n' + str(k2) for k1, k2 in zip(kpts1[0:10], kpts2[0:10])])) n = 4 #clip = min(len(kpts1), n) # HACK FIXME fxs = np.array(pyhestest.spaced_elements2(kpts2, n).tolist()[0:3]) print('fxs=%r' % fxs) kpts1 = kpts1[fxs] kpts2 = kpts2[fxs] desc1 = desc1[fxs] desc2 = desc2[fxs] print('\n----\n'.join([str(k1) + '\n' + str(k2) for k1, k2 in zip(kpts1, kpts2)])) imgBGR = pyhestest.cv2.imread(img_fpath) sel = min(len(kpts1) - 1, 3) TEST_keypoint(imgBGR, img_fpath, kpts1, desc1, sel, fnum=1, figtitle='Downward Rotation') TEST_keypoint(imgBGR, img_fpath, kpts2, desc2, sel, fnum=9001, figtitle='Adapted Rotation') #locals_ = TEST_keypoint(imgBGR, img_fpath, kpts1, desc1, sel) #exec(utool.execstr_dict(locals_, 'locals_')) #exec(utool.execstr_dict(f1_loc, 'f1_loc')) # NOQA #pinteract.interact_keypoints(imgBGR, kpts2, desc, arrow=True, rect=True) if ut.show_was_requested(): exec(df2.present())
def netrun(): r""" CommandLine: # --- UTILITY python -m ibeis_cnn --tf get_juction_dpath --show # --- DATASET BUILDING --- # Build Dataset Aliases python -m ibeis_cnn --tf netrun --db PZ_MTEST --acfg ctrl --ensuredata --show python -m ibeis_cnn --tf netrun --db PZ_Master1 --acfg timectrl --ensuredata python -m ibeis_cnn --tf netrun --db PZ_Master1 --acfg timectrl:pername=None --ensuredata python -m ibeis_cnn --tf netrun --db PZ_Master1 --acfg timectrl:pername=None --ensuredata python -m ibeis_cnn --tf netrun --db mnist --ensuredata --show python -m ibeis_cnn --tf netrun --db mnist --ensuredata --show --datatype=category python -m ibeis_cnn --tf netrun --db mnist --ensuredata --show --datatype=siam-patch python -m ibeis_cnn --tf netrun --db PZ_Master1 --acfg ctrl:pername=None,excluderef=False,contributor_contains=FlankHack --ensuredata --show --datatype=siam-part # Parts based datasets python -m ibeis_cnn --tf netrun --db PZ_MTEST --acfg ctrl --datatype=siam-part --ensuredata --show % Patch based dataset (big one) python -m ibeis_cnn --tf netrun --db PZ_Master1 --acfg default:is_known=True,qmin_pername=2,view=primary,species=primary,minqual=ok --ensuredata --show --vtd python -m ibeis_cnn --tf netrun --ds pzm4 --weights=new --arch=siaml2_128 --train --monitor python -m ibeis_cnn --tf netrun --ds pzm4 --arch=siaml2_128 --test python -m ibeis_cnn --tf netrun --ds pzm4 --arch=siaml2_128 --veryverbose --no-flask # --- TRAINING --- python -m ibeis_cnn --tf netrun --db PZ_Master1 --acfg default:is_known=True,qmin_pername=2,view=primary,species=primary,minqual=ok --weights=new --arch=siaml2_128 --train --monitor python -m ibeis_cnn --tf netrun --ds timectrl_pzmaster1 --acfg ctrl:pername=None,excluderef=False,contributor_contains=FlankHack --train --weights=new --arch=siaml2_128 --monitor # NOQA python -m ibeis_cnn --tf netrun --ds timectrl_pzmaster1 --acfg ctrl:pername=None,excluderef=False --train --weights=new --arch=siaml2_128 --monitor # NOQA python -m ibeis_cnn --tf netrun --ds pzmtest --weights=new --arch=siaml2_128 --train --monitor --DEBUG_AUGMENTATION python -m ibeis_cnn --tf netrun --ds pzmtest --weights=new --arch=siaml2_128 --train --monitor python -m ibeis_cnn --tf netrun --ds flankhack --weights=new --arch=siaml2_partmatch --train --monitor --learning_rate=.00001 python -m ibeis_cnn --tf netrun --ds flankhack --weights=new --arch=siam_deepfaceish --train --monitor --learning_rate=.00001 # Different ways to train mnist python -m ibeis_cnn --tf netrun --db mnist --weights=new --arch=mnist_siaml2 --train --monitor --datatype=siam-patch python -m ibeis_cnn --tf netrun --db mnist --weights=new --arch=mnist-category --train --monitor --datatype=category # --- INITIALIZED-TRAINING --- python -m ibeis_cnn --tf netrun --ds pzmtest --arch=siaml2_128 --weights=gz-gray:current --train --monitor # --- TESTING --- python -m ibeis_cnn --tf netrun --db liberty --weights=liberty:current --arch=siaml2_128 --test python -m ibeis_cnn --tf netrun --db PZ_Master0 --weights=combo:current --arch=siaml2_128 --testall Example: >>> # DISABLE_DOCTEST >>> from ibeis_cnn.netrun import * # NOQA >>> netrun() >>> ut.show_if_requested() """ ut.colorprint('[netrun] NET RUN', 'red') requests, hyperparams, tags = parse_args() ds_tag = tags['ds_tag'] datatype = tags['datatype'] extern_ds_tag = tags['extern_ds_tag'] arch_tag = tags['arch_tag'] checkpoint_tag = tags['checkpoint_tag'] # ---------------------------- # Choose the main dataset ut.colorprint('[netrun] Ensuring Dataset', 'yellow') dataset = ingest_data.grab_dataset(ds_tag, datatype) if extern_ds_tag is not None: extern_dpath = ingest_data.get_extern_training_dpath(extern_ds_tag) else: extern_dpath = None print('dataset.training_dpath = %r' % (dataset.training_dpath,)) print('Dataset Alias Key: %r' % (dataset.alias_key,)) print('Current Dataset Tag: %r' % ( ut.invert_dict(DS_TAG_ALIAS2).get(dataset.alias_key, None),)) if requests['ensuredata']: # Print alias key that maps to this particular dataset if ut.show_was_requested(): interact_ = dataset.interact() # NOQA return print('...exiting') sys.exit(1) # ---------------------------- # Choose model architecture # TODO: data will need to return info about number of labels in viewpoint models # Specify model archichitecture ut.colorprint('[netrun] Architecture Specification', 'yellow') if arch_tag == 'siam2stream': model = models.SiameseCenterSurroundModel( data_shape=dataset.data_shape, training_dpath=dataset.training_dpath, **hyperparams) elif arch_tag.startswith('siam'): model = models.SiameseL2( data_shape=dataset.data_shape, arch_tag=arch_tag, training_dpath=dataset.training_dpath, **hyperparams) elif arch_tag == 'mnist-category': model = models.MNISTModel( data_shape=dataset.data_shape, output_dims=dataset.output_dims, arch_tag=arch_tag, training_dpath=dataset.training_dpath, **hyperparams) pass else: raise ValueError('Unknown arch_tag=%r' % (arch_tag,)) ut.colorprint('[netrun] Initialize archchitecture', 'yellow') model.init_arch() # ---------------------------- # Choose weight initialization ut.colorprint('[netrun] Setting weights', 'yellow') if checkpoint_tag == 'new': ut.colorprint('[netrun] * Initializing new weights', 'lightgray') model.reinit_weights() else: checkpoint_tag = model.resolve_fuzzy_checkpoint_pattern( checkpoint_tag, extern_dpath) ut.colorprint('[netrun] * Resolving weights checkpoint_tag=%r' % (checkpoint_tag,), 'lightgray') if extern_dpath is not None: model.load_extern_weights(dpath=extern_dpath, checkpoint_tag=checkpoint_tag) elif model.has_saved_state(checkpoint_tag=checkpoint_tag): model.load_model_state(checkpoint_tag=checkpoint_tag) else: model_state_fpath = model.get_model_state_fpath( checkpoint_tag=checkpoint_tag) print('model_state_fpath = %r' % (model_state_fpath,)) ut.checkpath(model_state_fpath, verbose=True) print('Known checkpoints are: ' + ut.repr3(model.list_saved_checkpoints())) raise ValueError(('Unresolved weight init: ' 'checkpoint_tag=%r, extern_ds_tag=%r') % ( checkpoint_tag, extern_ds_tag,)) #print('Model State:') #print(model.get_state_str()) # ---------------------------- if not model.is_train_state_initialized(): ut.colorprint('[netrun] Need to initialize training state', 'yellow') X_train, y_train = dataset.subset('train') model.ensure_data_params(X_train, y_train) # Run Actions if requests['train']: ut.colorprint('[netrun] Training Requested', 'yellow') # parse training arguments config = ut.argparse_dict(dict( era_size=15, max_epochs=1200, rate_decay=.8, )) model.monitor_config.update(**config) X_train, y_train = dataset.subset('train') X_valid, y_valid = dataset.subset('valid') model.fit(X_train, y_train, X_valid=X_valid, y_valid=y_valid) elif requests['test']: #assert model.best_results['epoch'] is not None ut.colorprint('[netrun] Test Requested', 'yellow') if requests['testall']: ut.colorprint('[netrun] * Testing on all data', 'lightgray') X_test, y_test = dataset.subset('all') flat_metadata = dataset.subset_metadata('all') else: ut.colorprint('[netrun] * Testing on test subset', 'lightgray') X_test, y_test = dataset.subset('test') flat_metadata = dataset.subset_metadata('test') data, labels = X_test, y_test dataname = dataset.alias_key experiments.test_siamese_performance(model, data, labels, flat_metadata, dataname) else: if not ut.get_argflag('--cmd'): raise ValueError('nothing here. need to train or test') if requests['publish']: ut.colorprint('[netrun] Publish Requested', 'yellow') publish_dpath = ut.truepath('~/Dropbox/IBEIS') published_model_state = ut.unixjoin( publish_dpath, model.arch_tag + '_model_state.pkl') ut.copy(model.get_model_state_fpath(), published_model_state) ut.view_directory(publish_dpath) print('You need to get the dropbox link and ' 'register it into the appropriate file') # pip install dropbox # https://www.dropbox.com/developers/core/start/python # import dropbox # need oauth #client.share('/myfile.txt', short_url=False) # https://cthulhu.dyn.wildme.io/public/models/siaml2_128_model_state.pkl if ut.get_argflag('--cmd'): ut.embed()
def fourier_devtest(img): r""" Args: img (ndarray[uint8_t, ndim=2]): image data CommandLine: python -m vtool.quality_classifier --test-fourier_devtest --show References: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_transforms/py_fourier_transform/py_fourier_transform.html http://cns-alumni.bu.edu/~slehar/fourier/fourier.html Example: >>> # DISABLE_DOCTEST >>> from vtool.quality_classifier import * # NOQA >>> import vtool as vt >>> # build test data >>> img_fpath = ut.grab_test_imgpath('lena.png') >>> img = vt.imread(img_fpath, grayscale=True) >>> # execute function >>> magnitude_spectrum = fourier_devtest(img) """ import plottool as pt def pad_img(img): rows, cols = img.shape nrows = cv2.getOptimalDFTSize(rows) ncols = cv2.getOptimalDFTSize(cols) right = ncols - cols bottom = nrows - rows bordertype = cv2.BORDER_CONSTANT nimg = cv2.copyMakeBorder(img, 0, bottom, 0, right, bordertype, value=0) return nimg def convert_to_fdomain(img): dft = cv2.dft(img.astype(np.float32), flags=cv2.DFT_COMPLEX_OUTPUT) #dft_shift = np.fft.fftshift(dft) return dft def convert_from_fdomain(dft): img = cv2.idft(dft) img = cv2.magnitude(img[:, :, 0], img[:, :, 1]) img /= img.max() return img * 255.0 def get_fdomain_mag(dft_shift): magnitude_spectrum = np.log( cv2.magnitude(dft_shift[:, :, 0], dft_shift[:, :, 1])) return magnitude_spectrum def imgstats(img): print('stats:') print(' dtype = %r ' % (img.dtype, )) print(' ' + ut.get_stats_str(img, axis=None)) nimg = pad_img(img) dft = convert_to_fdomain(nimg) #freq_domain = np.fft.fft2(img) #freq_domain_shift = np.fft.fftshift(freq_domain) rows, cols = nimg.shape crow, ccol = rows / 2, cols / 2 # create a mask first, center square is 1, remaining all zeros mask = np.zeros((rows, cols, 2), np.uint8) mask[crow - 30:crow + 30, ccol - 30:ccol + 30] = 1 dft_mask = np.fft.ifftshift(np.fft.fftshift(dft) * mask) img_back = convert_from_fdomain(dft_mask) imgstats(dft) imgstats(mask) imgstats(nimg) imgstats(nimg) print('nimg.shape = %r' % (nimg.shape, )) print('dft_shift.shape = %r' % (dft.shape, )) if ut.show_was_requested(): #import plottool as pt next_pnum = pt.make_pnum_nextgen(nRows=3, nCols=2) pt.imshow(nimg, pnum=next_pnum(), title='nimg') pt.imshow(20 * get_fdomain_mag(dft), pnum=next_pnum(), title='mag(f)') pt.imshow(20 * get_fdomain_mag(dft_mask), pnum=next_pnum(), title='dft_mask') pt.imshow(img_back, pnum=next_pnum(), title='img_back') pt.show_if_requested()
def fix_pz_master(): r""" CommandLine: python -m ibeis.algo.hots.devcases --test-fix_pz_master --show Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.devcases import * # NOQA >>> # build test data >>> # execute function >>> result = fix_pz_master() >>> # verify results >>> print(result) """ # ReROI aid4513+name """ 82 97 117 118 157 213 299 336 351 368 392 415 430 434 441 629 664 679 682 685 695 835 1309 1317 1327 1382 1455 1816 3550 4067 4125 4131 4141 4191 4239 4242 4256 4257 4258 4439 4489 4625 4797 4800 4809 4812 4813 4819 4829 4831 4864 4865 4871 4877 4879 4885 4886 4891 4897 4899 4902 4904 4909 4912 4931 4933 4934 4935 4936 4952 5053 5073 5248 5249 5367 5776 5999 6150 6699 6882 7197 7225 7231 7237 7247 7254 7263 7280 7298 7357 7373 7385 7412 7424 7426 7464 7470 7472 7473 7479 7480 7507 7533 7535 7537 7578 7589 7629 7666 7669 7672 7720 7722 7734 7740 7754 7778 7792 7796 7798 7807 7812 7813 7829 7840 7846 7875 7876 7888 7889 7896 7899 7900 7901 7908 7909 7911 7915 7916 7917 7925 7931 7936 7938 7944 7947 7951 7954 7961 7965 7966 7978 7979 7981 7988 7992 7998 8019 8044 8045 8047 8051 8052 8059 8062 8063 8064 8066 8069 8074 8075 8083 8088 8093 8094 8095 8100 8102 8103 8105 8113 8116 8118 8119 8120 8123 8126 8128 8139 8144 8151 8152 8153 8154 8155 8157 8165 8170 8178 8180 8186 8188 8189 8195 8197 8198 8201 8202 8206 8213 8216 8226 8228 8231 8238 8245 8258 8265 8269 8276 8281 8285 8287 8297 8301 8305 8306 8308 8312 8318 8319 8321 8329 8332 8345 8349 8357 8361 8365 8367 8372 8373 8381 8386 8389 8392 8398 8399 8400 8402 8403 8406 8407 8412 8423 8424 8426 8427 8428 8429 8431 8439 8444 8446 8447 8450 8456 8457 8461 8463 8464 8466 8471 8472 8477 8481 8486 8489 8490 8494 8497 8499 8500 8501 8503 8506 8508 8535 8536 8537 8538 8539 8540 8541 8544 8545 8550 8552 8554 8555 8557 8558 8559 8564 8567 8568 8574 8575 8582 8584 8587 8589 8591 8592 8593 8596 8597 8601 8602 8605 8607 8608 8616 8617 8618 8619 8620 8621 8622 8629 8637 8639 8647 8662 8664 8665 8666 8673 8674 8676 8689 8691 8692 8693 8694 8699 8700 8702 8703 8712 8714 8715 8719 8724 8733 8734 8736 """ qaids_str = """ 82 117 118 213 299 336 351 368 392 430 434 441 495 616 629 664 679 682 685 695 835 915 1317 1382 3550 4239 4242 4246 4256 4257 4258 4439 4445 4447 4489 4706 4800 4812 4813 4819 4828 4829 4831 4864 4865 4871 4877 4879 4885 4886 4891 4897 4899 4902 4904 4909 4912 4933 4934 4936 4952 5053 5073 5248 5367 5776 7197 7225 7254 7263 7298 7309 7470 7473 7479 7507 7535 7570 7589 7666 7672 7722 7734 7740 7754 7760 7796 7798 7807 7813 7829 7840 7875 7876 7888 7889 7896 7899 7900 7901 7908 7909 7911 7916 7917 7925 7931 7934 7936 7938 7944 7947 7951 7954 7961 7964 7965 7966 7978 7979 7981 7988 7992 7998 8019 8044 8045 8047 8051 8052 8058 8059 8062 8063 8064 8066 8074 8075 8083 8088 8094 8095 8100 8101 8102 8103 8105 8111 8113 8116 8119 8120 8121 8123 8126 8128 8144 8151 8152 8153 8155 8156 8157 8165 8170 8180 8186 8188 8198 8201 8206 8213 8216 8226 8228 8231 8238 8258 8276 8281 8285 8287 8295 8297 8301 8305 8306 8308 8312 8318 8319 8329 8332 8355 8357 8361 8365 8367 8372 8373 8381 8386 8388 8389 8392 8398 8399 8402 8403 8406 8407 8412 8424 8425 8426 8428 8429 8439 8442 8444 8446 8447 8449 8450 8452 8456 8457 8461 8463 8464 8466 8470 8471 8481 8486 8489 8490 8494 8497 8499 8500 8501 8503 8506 8508 8535 8536 8537 8538 8539 8540 8544 8545 8550 8554 8555 8557 8558 8559 8563 8564 8567 8574 8575 8582 8584 8587 8589 8592 8593 8596 8597 8600 8601 8604 8605 8607 8608 8616 8617 8618 8619 8620 8621 8622 8623 8629 8637 8639 8647 8662 8665 8666 8673 8674 8676 8691 8693 8694 8699 8700 8702 8703 8712 8714 8715 8719 8724 8731 8733 8734 8736 """ qaids_ = map(int, filter(len, qaids_str.replace('\n', ' ').split(' '))) import ibeis ibeis._preload() from ibeis.gui import inspect_gui import guitool ibs = ibeis.opendb('PZ_Master0') #ibs._default_config() #ibs.cfg.save() daids = ibs.get_valid_aids(minqual='poor') qaids = ibs.filter_junk_annotations(qaids_) #qaids = qaids[64:128] qreq_ = ibs.new_query_request(qaids, daids) #qreq_.lazy_load() qres_list = ibs.query_chips(qreq_=qreq_, verbose=True) qres_wgt = inspect_gui.launch_review_matches_interface(ibs, qres_list, dodraw=ut.show_was_requested()) if ut.show_was_requested(): guitool.guitool_main.qtapp_loop() return qres_wgt
def do_infr_test(ccs, edges, new_edges): """ Creates a graph with `ccs` + `edges` and then adds `new_edges` """ # import networkx as nx import wbia.plottool as pt infr = demo.make_demo_infr(ccs, edges) if ut.show_was_requested(): pt.qtensure() # Preshow fnum = 1 if ut.show_was_requested(): infr.set_node_attrs('shape', 'circle') infr.show( pnum=(2, 1, 1), fnum=fnum, show_unreviewed_edges=True, show_reviewed_cuts=True, splines='spline', show_inferred_diff=True, groupby='name_label', show_labels=True, pickable=True, ) pt.set_title('pre-review') pt.gca().set_aspect('equal') infr.set_node_attrs('pin', 'true') # fig1 = pt.gcf() # fig1.canvas.mpl_connect('pick_event', ut.partial(on_pick, infr=infr)) infr1 = infr infr2 = infr.copy() for new_edge in new_edges: aid1, aid2, data = new_edge evidence_decision = data['evidence_decision'] infr2.add_feedback((aid1, aid2), evidence_decision) infr2.relabel_using_reviews(rectify=False) infr2.apply_nondynamic_update() # Postshow if ut.show_was_requested(): infr2.show( pnum=(2, 1, 2), fnum=fnum, show_unreviewed_edges=True, show_inferred_diff=True, show_labels=True, ) pt.gca().set_aspect('equal') pt.set_title('post-review') # fig2 = pt.gcf() # if fig2 is not fig1: # fig2.canvas.mpl_connect('pick_event', ut.partial(on_pick, infr=infr2)) class Checker(object): """ Asserts pre and post test properties of the graph """ def __init__(self, infr1, infr2): self._errors = [] self.infr1 = infr1 self.infr2 = infr2 def __call__(self, infr, u, v, key, val, msg): data = infr.get_nonvisual_edge_data((u, v)) if data is None: assert infr.graph.has_edge( u, v), 'uv=%r, %r does not exist' % (u, v) got = data.get(key) if got != val: msg1 = 'key=%s %r!=%r, ' % (key, got, val) errmsg = ''.join([ msg1, msg, '\nedge=', ut.repr2((u, v)), '\n', infr.repr_edge_data(data), ]) self._errors.append(errmsg) def custom_precheck(self, func): try: func(self.infr1) except AssertionError as ex: self._errors.append(str(ex)) def after(self, errors=[]): """ Delays error reporting until after visualization prints errors, then shows you the graph, then finally if any errors were discovered they are raised """ errors = errors + self._errors if errors: ut.cprint('PRINTING %d FAILURE' % (len(errors)), 'red') for msg in errors: logger.info(msg) ut.cprint('HAD %d FAILURE' % (len(errors)), 'red') if ut.show_was_requested(): pt.all_figures_tile(percent_w=0.5) ut.show_if_requested() if errors: raise AssertionError('There were errors') check = Checker(infr1, infr2) return infr1, infr2, check
def test_featweight_worker(): """ test function python -m ibeis.algo.preproc.preproc_featweight --test-gen_featweight_worker --show --cnn """ import ibeis qreq_ = ibeis.main_helpers.testdata_qreq_(defaultdb='PZ_MTEST', p=['default:fw_detector=cnn'], qaid_override=[1]) ibs = qreq_.ibs config2_ = qreq_.qparams lazy = True aid_list = qreq_.get_external_qaids() #aid_list = ibs.get_valid_aids()[0:30] kpts_list = ibs.get_annot_kpts(aid_list) chipsize_list = ibs.get_annot_chip_sizes(aid_list, config2_=config2_) probchip_fpath_list = preproc_probchip.compute_and_write_probchip(ibs, aid_list, lazy=lazy, config2_=config2_) print('probchip_fpath_list = %r' % (probchip_fpath_list,)) probchip_list = [vt.imread(fpath, grayscale=True) if exists(fpath) else None for fpath in probchip_fpath_list] _iter = list(zip(aid_list, kpts_list, probchip_list, chipsize_list)) _iter = ut.InteractiveIter(_iter, enabled=ut.get_argflag('--show')) for aid, kpts, probchip, chipsize in _iter: #kpts = kpts_list[0] #aid = aid_list[0] #probchip = probchip_list[0] #chipsize = chipsize_list[0] tup = (aid, kpts, probchip, chipsize) (aid, weights) = gen_featweight_worker(tup) if aid == 3 and ibs.get_dbname() == 'testdb1': # Run Asserts if not interactive weights_03_test = weights[0:3] print('weights[0:3] = %r' % (weights_03_test,)) #weights_03_target = [ 0.098, 0.155, 0.422] #weights_03_target = [ 0.324, 0.407, 0.688] #weights_thresh = [ 0.09, 0.09, 0.09] #ut.assert_almost_eq(weights_03_test, weights_03_target, weights_thresh) ut.assert_inbounds(weights_03_test, 0, 1) if not ut.show_was_requested(): break if ut.show_was_requested(): import plottool as pt #sfx, sfy = (probchip.shape[1] / chipsize[0], probchip.shape[0] / chipsize[1]) #kpts_ = vt.offset_kpts(kpts, (0, 0), (sfx, sfy)) pnum_ = pt.make_pnum_nextgen(1, 3) # *pt.get_square_row_cols(4)) fnum = 1 pt.figure(fnum=fnum, doclf=True) ### pt.imshow(ibs.get_annot_chips(aid, config2_=config2_), pnum=pnum_(0), fnum=fnum) if ut.get_argflag('--numlbl'): pt.gca().set_xlabel('(1)') ### pt.imshow(probchip, pnum=pnum_(2), fnum=fnum) if ut.get_argflag('--numlbl'): pt.gca().set_xlabel('(2)') #pt.draw_kpts2(kpts_, ell_alpha=.4, color_list=pt.ORANGE) ### #pt.imshow(probchip, pnum=pnum_(3), fnum=fnum) #color_list = pt.draw_kpts2(kpts_, weights=weights, ell_alpha=.7, cmap_='jet') #cb = pt.colorbar(weights, color_list) #cb.set_label('featweights') ### pt.imshow(ibs.get_annot_chips(aid, config2_=qreq_.qparams), pnum=pnum_(1), fnum=fnum) #color_list = pt.draw_kpts2(kpts, weights=weights, ell_alpha=.3, cmap_='jet') color_list = pt.draw_kpts2(kpts, weights=weights, ell_alpha=.3) cb = pt.colorbar(weights, color_list) cb.set_label('featweights') if ut.get_argflag('--numlbl'): pt.gca().set_xlabel('(3)') #pt.draw_kpts2(kpts, ell_alpha=.4) pt.draw() pt.show_if_requested()