def compute_weighte_average_score(match): """ old scoring measure """ import vtool as vt # Get distinctivness and forground of matching points fx1_list, fx2_list = match.fm.T annot1 = match.annot1 annot2 = match.annot2 dstncvs1 = annot1.dstncvs.take(fx1_list) dstncvs2 = annot2.dstncvs.take(fx2_list) fgweight1 = annot1.fgweights.take(fx1_list) fgweight2 = annot2.fgweights.take(fx2_list) dstncvs = np.sqrt(dstncvs1 * dstncvs2) fgweight = np.sqrt(fgweight1 * fgweight2) fsv = np.vstack((match.fs, dstncvs, fgweight)).T fs_new = vt.weighted_average_scoring(fsv, [0], [1, 2]) weight_ave_score = fs_new.sum() return weight_ave_score
def apply_new_qres_filter_scores(qreq_vsone_, qres_vsone, newfsv_list, newscore_aids, filtkey): r""" applies the new filter scores vectors to a query result and updates other scores Args: qres_vsone (QueryResult): object of feature correspondences and scores newfsv_list (list): newscore_aids (?): filtkey (?): CommandLine: python -m ibeis.algo.hots.special_query --test-apply_new_qres_filter_scores Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.special_query import * # NOQA >>> ibs, valid_aids = testdata_special_query() >>> qaids = valid_aids[0:1] >>> daids = valid_aids[1:] >>> qaid = qaids[0] >>> filtkey = hstypes.FiltKeys.DISTINCTIVENESS >>> use_cache = False >>> qaid2_qres_vsmany, qreq_vsmany_ = query_vsmany_initial(ibs, qaids, daids, use_cache) >>> vsone_query_pairs = build_vsone_shortlist(ibs, qaid2_qres_vsmany) >>> qaid2_qres_vsone, qreq_vsone_ = query_vsone_pairs(ibs, vsone_query_pairs, use_cache) >>> qreq_vsone_.load_score_normalizer() >>> qres_vsone = qaid2_qres_vsone[qaid] >>> qres_vsmany = qaid2_qres_vsmany[qaid] >>> top_aids = vsone_query_pairs[0][1] >>> newfsv_list, newscore_aids = get_new_qres_distinctiveness(qres_vsone, qres_vsmany, top_aids, filtkey) >>> apply_new_qres_filter_scores(qreq_vsone_, qres_vsone, newfsv_list, newscore_aids, filtkey) Ignore: qres_vsone.show_top(ibs, name_scoring=True) print(qres_vsone.get_inspect_str(ibs=ibs, name_scoring=True)) print(qres_vsmany.get_inspect_str(ibs=ibs, name_scoring=True)) """ assert ut.listfind(qres_vsone.filtkey_list, filtkey) is None # HACK to update result cfgstr qres_vsone.filtkey_list.append(filtkey) qres_vsone.cfgstr = qreq_vsone_.get_cfgstr() # Find positions of weight filters and score filters # so we can apply a weighted average #numer_filters = [hstypes.FiltKeys.LNBNN, hstypes.FiltKeys.RATIO] weight_filters = hstypes.WEIGHT_FILTERS weight_filtxs, nonweight_filtxs = vt.index_partition( qres_vsone.filtkey_list, weight_filters) for new_fsv_vsone, daid in zip(newfsv_list, newscore_aids): #scorex_vsone = ut.listfind(qres_vsone.filtkey_list, filtkey) #if scorex_vsone is None: # TODO: add spatial verification as a filter score # augment the vsone scores # TODO: paramaterize weighted_ave_score = True if weighted_ave_score: # weighted average scoring new_fs_vsone = vt.weighted_average_scoring(new_fsv_vsone, weight_filtxs, nonweight_filtxs) else: # product scoring new_fs_vsone = product_scoring(new_fsv_vsone) new_score_vsone = new_fs_vsone.sum() qres_vsone.aid2_fsv[daid] = new_fsv_vsone qres_vsone.aid2_fs[daid] = new_fs_vsone qres_vsone.aid2_score[daid] = new_score_vsone # FIXME: this is not how to compute new probability #if qres_vsone.aid2_prob is not None: # qres_vsone.aid2_prob[daid] = qres_vsone.aid2_score[daid] # This is how to compute new probability if qreq_vsone_.qparams.score_normalization: # FIXME: TODO: Have unsupported scores be represented as Nones # while score normalizer is still being trained. normalizer = qreq_vsone_.normalizer daid2_score = qres_vsone.aid2_score score_list = list(six.itervalues(daid2_score)) daid_list = list(six.iterkeys(daid2_score)) prob_list = normalizer.normalize_score_list(score_list) daid2_prob = dict(zip(daid_list, prob_list)) qres_vsone.aid2_prob = daid2_prob
def apply_new_qres_filter_scores(qreq_vsone_, qres_vsone, newfsv_list, newscore_aids, filtkey): r""" applies the new filter scores vectors to a query result and updates other scores Args: qres_vsone (QueryResult): object of feature correspondences and scores newfsv_list (list): newscore_aids (?): filtkey (?): CommandLine: python -m ibeis.algo.hots.special_query --test-apply_new_qres_filter_scores Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.special_query import * # NOQA >>> ibs, valid_aids = testdata_special_query() >>> qaids = valid_aids[0:1] >>> daids = valid_aids[1:] >>> qaid = qaids[0] >>> filtkey = hstypes.FiltKeys.DISTINCTIVENESS >>> use_cache = False >>> qaid2_qres_vsmany, qreq_vsmany_ = query_vsmany_initial(ibs, qaids, daids, use_cache) >>> vsone_query_pairs = build_vsone_shortlist(ibs, qaid2_qres_vsmany) >>> qaid2_qres_vsone, qreq_vsone_ = query_vsone_pairs(ibs, vsone_query_pairs, use_cache) >>> qreq_vsone_.load_score_normalizer() >>> qres_vsone = qaid2_qres_vsone[qaid] >>> qres_vsmany = qaid2_qres_vsmany[qaid] >>> top_aids = vsone_query_pairs[0][1] >>> newfsv_list, newscore_aids = get_new_qres_distinctiveness(qres_vsone, qres_vsmany, top_aids, filtkey) >>> apply_new_qres_filter_scores(qreq_vsone_, qres_vsone, newfsv_list, newscore_aids, filtkey) Ignore: qres_vsone.show_top(ibs, name_scoring=True) print(qres_vsone.get_inspect_str(ibs=ibs, name_scoring=True)) print(qres_vsmany.get_inspect_str(ibs=ibs, name_scoring=True)) """ assert ut.listfind(qres_vsone.filtkey_list, filtkey) is None # HACK to update result cfgstr qres_vsone.filtkey_list.append(filtkey) qres_vsone.cfgstr = qreq_vsone_.get_cfgstr() # Find positions of weight filters and score filters # so we can apply a weighted average #numer_filters = [hstypes.FiltKeys.LNBNN, hstypes.FiltKeys.RATIO] weight_filters = hstypes.WEIGHT_FILTERS weight_filtxs, nonweight_filtxs = vt.index_partition(qres_vsone.filtkey_list, weight_filters) for new_fsv_vsone, daid in zip(newfsv_list, newscore_aids): #scorex_vsone = ut.listfind(qres_vsone.filtkey_list, filtkey) #if scorex_vsone is None: # TODO: add spatial verification as a filter score # augment the vsone scores # TODO: paramaterize weighted_ave_score = True if weighted_ave_score: # weighted average scoring new_fs_vsone = vt.weighted_average_scoring(new_fsv_vsone, weight_filtxs, nonweight_filtxs) else: # product scoring new_fs_vsone = product_scoring(new_fsv_vsone) new_score_vsone = new_fs_vsone.sum() qres_vsone.aid2_fsv[daid] = new_fsv_vsone qres_vsone.aid2_fs[daid] = new_fs_vsone qres_vsone.aid2_score[daid] = new_score_vsone # FIXME: this is not how to compute new probability #if qres_vsone.aid2_prob is not None: # qres_vsone.aid2_prob[daid] = qres_vsone.aid2_score[daid] # This is how to compute new probability if qreq_vsone_.qparams.score_normalization: # FIXME: TODO: Have unsupported scores be represented as Nones # while score normalizer is still being trained. normalizer = qreq_vsone_.normalizer daid2_score = qres_vsone.aid2_score score_list = list(six.itervalues(daid2_score)) daid_list = list(six.iterkeys(daid2_score)) prob_list = normalizer.normalize_score_list(score_list) daid2_prob = dict(zip(daid_list, prob_list)) qres_vsone.aid2_prob = daid2_prob