def testdata_chipmatch(): from ibeis.algo.hots import chip_match # only the first indicies will matter in these test # feature matches fm_list = [ np.array([(0, 9), (1, 9), (2, 9), (3, 9)], dtype=np.int32), np.array([(0, 9), (1, 9), (2, 9), (3, 9)], dtype=np.int32), np.array([(0, 9), (1, 9), (2, 9), (3, 9)], dtype=np.int32), np.array([(4, 9), (5, 9), (6, 9), (3, 9)], dtype=np.int32), np.array([(0, 9), (1, 9), (2, 9), (3, 9), (4, 9)], dtype=np.int32) ] # score each feature match as 1 fsv_list = [ np.array([(1,), (1,), (1,), (1,)], dtype=hstypes.FS_DTYPE), np.array([(1,), (1,), (1,), (1,)], dtype=hstypes.FS_DTYPE), np.array([(1,), (1,), (1,), (1,)], dtype=hstypes.FS_DTYPE), np.array([(1,), (1,), (1,), (1,)], dtype=hstypes.FS_DTYPE), np.array([(1,), (1,), (1,), (1,), (1, )], dtype=hstypes.FS_DTYPE), ] cm = chip_match.ChipMatch( qaid=1, daid_list=np.array([1, 2, 3, 4, 5], dtype=np.int32), fm_list=fm_list, fsv_list=fsv_list, dnid_list=np.array([1, 1, 2, 2, 3], dtype=np.int32), fsv_col_lbls=['count'], ) #print(cm.get_rawinfostr()) #if False: # # DEBUG # cm.rrr() # print(cm.get_rawinfostr()) # print(cm.get_cvs_str(ibs=qreq_.ibs, numtop=None)) return cm
def testdata_chipmatch(): from ibeis.algo.hots import chip_match # only the first indicies will matter in these test # feature matches fm_list = [ np.array([(0, 9), (1, 9), (2, 9), (3, 9)], dtype=np.int32), np.array([(0, 9), (1, 9), (2, 9), (3, 9)], dtype=np.int32), np.array([(0, 9), (1, 9), (2, 9), (3, 9)], dtype=np.int32), np.array([(4, 9), (5, 9), (6, 9), (3, 9)], dtype=np.int32), np.array([(0, 9), (1, 9), (2, 9), (3, 9), (4, 9)], dtype=np.int32) ] # score each feature match as 1 fsv_list = [ np.array([(1, ), (1, ), (1, ), (1, )], dtype=hstypes.FS_DTYPE), np.array([(1, ), (1, ), (1, ), (1, )], dtype=hstypes.FS_DTYPE), np.array([(1, ), (1, ), (1, ), (1, )], dtype=hstypes.FS_DTYPE), np.array([(1, ), (1, ), (1, ), (1, )], dtype=hstypes.FS_DTYPE), np.array([(1, ), (1, ), (1, ), (1, ), (1, )], dtype=hstypes.FS_DTYPE), ] cm = chip_match.ChipMatch( qaid=1, daid_list=np.array([1, 2, 3, 4, 5], dtype=np.int32), fm_list=fm_list, fsv_list=fsv_list, dnid_list=np.array([1, 1, 2, 2, 3], dtype=np.int32), fsv_col_lbls=['count'], ) return cm
def make_empty_chip_matches(qreq_): """ returns empty query results for each external qaid Returns: list: cm_list CommandLine: python -m ibeis.algo.hots.query_request --exec-make_empty_chip_matches Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.hots.query_request import * # NOQA >>> import ibeis >>> qreq_ = ibeis.main_helpers.testdata_qreq_() >>> cm_list = qreq_.make_empty_chip_matches() >>> cm = cm_list[0] >>> cm.print_rawinfostr() >>> result = ('cm_list = %s' % (str(cm_list),)) >>> print(result) """ external_qaids = qreq_.get_external_qaids() #external_daids = qreq_.get_external_daids() #external_dnids = qreq_.ibs.get_annot_name_rowids(external_daids) # FIXME: hacky cm_list = [ chip_match.ChipMatch(qaid, [], qnid=qreq_.ibs.get_annot_name_rowids(qaid)) for qaid in (external_qaids) ] for cm in cm_list: cm._empty_hack() return cm_list
def match_single(smk, qaid, daids, qreq_, verbose=True): """ CommandLine: python -m ibeis.algo.smk.smk_pipeline SMK.match_single --profile python -m ibeis.algo.smk.smk_pipeline SMK.match_single --show python -m ibeis SMK.match_single -a ctrl:qmingt=2 --profile --db PZ_Master1 python -m ibeis SMK.match_single -a ctrl --profile --db GZ_ALL Example: >>> # FUTURE_ENABLE >>> from ibeis.algo.smk.smk_pipeline import * # NOQA >>> import ibeis >>> qreq_ = ibeis.testdata_qreq_(defaultdb='PZ_MTEST') >>> ibs = qreq_.ibs >>> daids = qreq_.daids >>> #ibs, daids = ibeis.testdata_aids(defaultdb='PZ_MTEST', default_set='dcfg') >>> qreq_ = SMKRequest(ibs, daids[0:1], daids, {'agg': True, >>> 'num_words': 1000, >>> 'sv_on': True}) >>> qreq_.ensure_data() >>> qaid = qreq_.qaids[0] >>> daids = qreq_.daids >>> daid = daids[1] >>> verbose = True >>> cm = qreq_.smk.match_single(qaid, daids, qreq_) >>> ut.quit_if_noshow() >>> ut.qtensure() >>> cm.ishow_analysis(qreq_) >>> ut.show_if_requested() """ from ibeis.algo.hots import chip_match from ibeis.algo.hots import pipeline alpha = qreq_.qparams['smk_alpha'] thresh = qreq_.qparams['smk_thresh'] agg = qreq_.qparams['agg'] #nAnnotPerName = qreq_.qparams.nAnnotPerNameSVER sv_on = qreq_.qparams.sv_on if sv_on: nNameShortList = qreq_.qparams.nNameShortlistSVER shortsize = nNameShortList else: shortsize = None X = qreq_.qinva.get_annot(qaid) # Determine which database annotations need to be checked #with ut.Timer('searching qaid=%r' % (qaid,), verbose=verbose): hit_inva_wxs = ut.take(qreq_.dinva.wx_to_aids, X.wx_list) hit_daids = np.array(list(set(ut.iflatten(hit_inva_wxs)))) # Mark impossible daids #with ut.Timer('checking impossible daids=%r' % (qaid,), verbose=verbose): valid_flags = check_can_match(qaid, hit_daids, qreq_) valid_daids = hit_daids.compress(valid_flags) shortlist = ut.Shortlist(shortsize) #gammaX = smk.gamma(X, wx_to_weight, agg, alpha, thresh) _prog = ut.ProgPartial(lbl='smk scoring qaid=%r' % (qaid, ), enabled=verbose, bs=True, adjust=True) wx_to_weight = qreq_.dinva.wx_to_weight debug = False if debug: qnid = qreq_.get_qreq_annot_nids([qaid])[0] daids = np.array(qreq_.daids) dnids = qreq_.get_qreq_annot_nids(daids) correct_aids = daids[np.where(dnids == qnid)[0]] daid = correct_aids[0] if agg: for daid in _prog(valid_daids): Y = qreq_.dinva.get_annot(daid) item = match_kernel_agg(X, Y, wx_to_weight, alpha, thresh) shortlist.insert(item) else: for daid in _prog(valid_daids): Y = qreq_.dinva.get_annot(daid) item = match_kernel_sep(X, Y, wx_to_weight, alpha, thresh) shortlist.insert(item) # Build chipmatches for the shortlist results #with ut.Timer('build cms', verbose=verbose): cm = chip_match.ChipMatch(qaid=qaid, fsv_col_lbls=['smk']) cm.daid_list = [] cm.fm_list = [] cm.fsv_list = [] _prog = ut.ProgPartial(lbl='smk build cm qaid=%r' % (qaid, ), enabled=verbose, bs=True, adjust=True) for item in _prog(shortlist): (score, score_list, Y, X_idx, Y_idx) = item X_fxs = ut.take(X.fxs_list, X_idx) Y_fxs = ut.take(Y.fxs_list, Y_idx) # Only build matches for those that sver will use if agg: X_maws = ut.take(X.maws_list, X_idx) Y_maws = ut.take(Y.maws_list, Y_idx) fm, fs = smk_funcs.build_matches_agg(X_fxs, Y_fxs, X_maws, Y_maws, score_list) else: fm, fs = smk_funcs.build_matches_sep(X_fxs, Y_fxs, score_list) if len(fm) > 0: #assert not np.any(np.isnan(fs)) daid = Y.aid fsv = fs[:, None] cm.daid_list.append(daid) cm.fm_list.append(fm) cm.fsv_list.append(fsv) cm._update_daid_index() cm.arraycast_self() cm.score_name_maxcsum(qreq_) #if False: # cm.assert_self(qreq_=qreq_, verbose=True) if sv_on: cm = pipeline.sver_single_chipmatch(qreq_, cm, verbose=verbose) cm.score_name_maxcsum(qreq_) return cm