Example #1
0
 def main():
     from ibeis.algo.hots.smk import smk_debug
     from ibeis.algo.hots.smk import smk_match
     from ibeis.algo.hots import pipeline
     ibs, taids, daids, qaids, qreq_ = smk_debug.testdata_ibeis2()
     qaid2_scores, qaid2_chipmatch = smk_match.execute_smk_L5(qreq_)
     filt2_meta = {}
     qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, filt2_meta, qreq_)
     qres = qaid2_qres_[qaids[0]]
     fig = qres.show_top(ibs)
     fig.show()
Example #2
0
 def main():
     from ibeis.algo.hots.smk import smk_debug
     from ibeis.algo.hots.smk import smk_match
     from ibeis.algo.hots import pipeline
     ibs, taids, daids, qaids, qreq_ = smk_debug.testdata_ibeis2()
     qaid2_scores, qaid2_chipmatch = smk_match.execute_smk_L5(qreq_)
     filt2_meta = {}
     qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch,
                                                 filt2_meta, qreq_)
     qres = qaid2_qres_[qaids[0]]
     fig = qres.show_top(ibs)
     fig.show()
Example #3
0
def query_smk_test(annots_df, invindex, qreq_):
    """
    ibeis interface
    Example:
        >>> from ibeis.algo.hots.smk import smk_match
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, annots_df, daids, qaids, invindex, qreq_ = smk_debug.testdata_internals_full()
        >>> qaid2_qres_ = smk_match.query_smk(annots_df, invindex, qreq_)

    Dev::
        qres = qaid2_qres_[qaids[0]]
        fig = qres.show_top(ibs)

    """
    from ibeis.algo.hots import pipeline
    from ibeis.algo.hots.smk import smk_match  # NOQA
    qaids = qreq_.get_external_qaids()
    qaid2_chipmatch = {}
    qaid2_scores = {}
    aggregate = qreq_.qparams.aggregate
    smk_alpha = qreq_.qparams.smk_alpha
    smk_thresh = qreq_.qparams.smk_thresh
    lbl = '[smk_match] asmk query: ' if aggregate else '[smk_match] smk query: '
    withinfo = True
    for qaid in ut.ProgressIter(enumerate(qaids), lbl=lbl, freq=1):
        daid2_score, daid2_chipmatch = smk_match.query_inverted_index(
            annots_df, qaid, invindex, withinfo, aggregate, smk_alpha,
            smk_thresh)
        qaid2_scores[qaid] = daid2_score
        qaid2_chipmatch[qaid] = daid2_chipmatch
    try:
        #filt2_meta = {}
        cm_list = convert_smkmatch_to_chipmatch(qaid2_chipmatch, qaid2_scores)
        #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, filt2_meta, qreq_)
        qaid2_qres_ = pipeline.chipmatch_to_resdict(qreq_, cm_list)
    except Exception as ex:
        ut.printex(ex)
        ut.qflag()
        raise
    return qaid2_qres_
Example #4
0
def query_smk_test(annots_df, invindex, qreq_):
    """
    ibeis interface
    Example:
        >>> from ibeis.algo.hots.smk import smk_match
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, annots_df, daids, qaids, invindex, qreq_ = smk_debug.testdata_internals_full()
        >>> qaid2_qres_ = smk_match.query_smk(annots_df, invindex, qreq_)

    Dev::
        qres = qaid2_qres_[qaids[0]]
        fig = qres.show_top(ibs)

    """
    from ibeis.algo.hots import pipeline
    from ibeis.algo.hots.smk import smk_match  # NOQA
    qaids = qreq_.get_external_qaids()
    qaid2_chipmatch = {}
    qaid2_scores    = {}
    aggregate = qreq_.qparams.aggregate
    smk_alpha     = qreq_.qparams.smk_alpha
    smk_thresh    = qreq_.qparams.smk_thresh
    lbl = '[smk_match] asmk query: ' if aggregate else '[smk_match] smk query: '
    withinfo = True
    for qaid in ut.ProgressIter(enumerate(qaids), lbl=lbl, freq=1):
        daid2_score, daid2_chipmatch = smk_match.query_inverted_index(
            annots_df, qaid, invindex, withinfo, aggregate, smk_alpha, smk_thresh)
        qaid2_scores[qaid]    = daid2_score
        qaid2_chipmatch[qaid] = daid2_chipmatch
    try:
        #filt2_meta = {}
        cm_list = convert_smkmatch_to_chipmatch(qaid2_chipmatch, qaid2_scores)
        #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, filt2_meta, qreq_)
        qaid2_qres_ = pipeline.chipmatch_to_resdict(qreq_, cm_list)
    except Exception as ex:
        ut.printex(ex)
        ut.qflag()
        raise
    return qaid2_qres_
Example #5
0
def get_query_components(ibs, qaids):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        qaids (?):

    Returns:
        ?:

    CommandLine:
        python -m ibeis.algo.hots.query_helpers --test-get_query_components

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.query_helpers import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> qaids = ibs.get_valid_aids()
        >>> # execute function
        >>> result = get_query_components(ibs, qaids)
        >>> # verify results
        >>> print(result)
    """
    from ibeis.algo.hots import pipeline
    from ibeis.algo.hots import query_request
    daids = ibs.get_valid_aids()
    cfgdict = dict(with_metadata=True)
    qreq_ = query_request.new_ibeis_query_request(ibs, qaids, daids, cfgdict)
    qaid = qaids[0]
    assert len(daids) > 0, '!!! nothing to search'
    assert len(qaids) > 0, '!!! nothing to query'
    qreq_.lazy_load()
    pipeline_locals_ = pipeline.testrun_pipeline_upto(qreq_, None)
    qaid2_nns            = pipeline_locals_['qaid2_nns']
    qaid2_nnvalid0       = pipeline_locals_['qaid2_nnvalid0']
    qaid2_filtweights    = pipeline_locals_['qaid2_filtweights']
    qaid2_nnfilts        = pipeline_locals_['qaid2_nnfilts']
    qaid2_chipmatch_FILT = pipeline_locals_['qaid2_chipmatch_FILT']
    qaid2_chipmatch_SVER = pipeline_locals_['qaid2_chipmatch_SVER']
    qaid2_svtups = qreq_.metadata['qaid2_svtups']
    #---
    qaid2_qres = pipeline.chipmatch_to_resdict(qreq_, qaid2_chipmatch_SVER)
    #####################
    # Testing components
    #####################
    with ut.Indenter('[components]'):
        qfx2_idx, qfx2_dist = qaid2_nns[qaid]
        qfx2_aid = qreq_.indexer.get_nn_aids(qfx2_idx)
        qfx2_fx  = qreq_.indexer.get_nn_featxs(qfx2_idx)
        qfx2_gid = ibs.get_annot_gids(qfx2_aid)  # NOQA
        qfx2_nid = ibs.get_annot_name_rowids(qfx2_aid)  # NOQA
        filtkey_list, qfx2_scores, qfx2_valids = qaid2_nnfilts[qaid]
        qaid2_nnfilt_ORIG    = pipeline.identity_filter(qreq_, qaid2_nns)
        qaid2_chipmatch_ORIG = pipeline.build_chipmatches(qreq_, qaid2_nns, qaid2_nnfilt_ORIG)
        qaid2_qres_ORIG = pipeline.chipmatch_to_resdict(qaid2_chipmatch_ORIG, qreq_)
        qaid2_qres_FILT = pipeline.chipmatch_to_resdict(qaid2_chipmatch_FILT, qreq_)
        qaid2_qres_SVER = qaid2_qres
    #####################
    # Relevant components
    #####################
    qaid = qaids[0]
    qres_ORIG = qaid2_qres_ORIG[qaid]
    qres_FILT = qaid2_qres_FILT[qaid]
    qres_SVER = qaid2_qres_SVER[qaid]

    return locals()
Example #6
0
def main_smk_debug():
    """
    CommandLine:
        python -m ibeis.algo.hots.smk.smk_debug --test-main_smk_debug

    Example:
        >>> from ibeis.algo.hots.smk.smk_debug import *  # NOQA
        >>> main_smk_debug()
    """
    print('+------------')
    print('SMK_DEBUG MAIN')
    print('+------------')
    from ibeis.algo.hots import pipeline
    ibs, annots_df, taids, daids, qaids, qreq_, nWords = testdata_dataframe()
    # Query using SMK
    #qaid = qaids[0]
    nWords     = qreq_.qparams.nWords
    aggregate  = qreq_.qparams.aggregate
    smk_alpha  = qreq_.qparams.smk_alpha
    smk_thresh = qreq_.qparams.smk_thresh
    nAssign    = qreq_.qparams.nAssign
    #aggregate = ibs.cfg.query_cfg.smk_cfg.aggregate
    #smk_alpha = ibs.cfg.query_cfg.smk_cfg.smk_alpha
    #smk_thresh = ibs.cfg.query_cfg.smk_cfg.smk_thresh
    print('+------------')
    print('SMK_DEBUG PARAMS')
    print('[smk_debug] aggregate = %r' % (aggregate,))
    print('[smk_debug] smk_alpha   = %r' % (smk_alpha,))
    print('[smk_debug] smk_thresh  = %r' % (smk_thresh,))
    print('[smk_debug] nWords  = %r' % (nWords,))
    print('[smk_debug] nAssign = %r' % (nAssign,))
    print('L------------')
    # Learn vocabulary
    #words = qreq_.words = smk_index.learn_visual_words(annots_df, taids, nWords)
    # Index a database of annotations
    #qreq_.invindex = smk_repr.index_data_annots(annots_df, daids, words, aggregate, smk_alpha, smk_thresh)
    qreq_.ibs = ibs
    # Smk Mach
    print('+------------')
    print('SMK_DEBUG MATCH KERNEL')
    print('+------------')
    qaid2_scores, qaid2_chipmatch_SMK = smk_match.execute_smk_L5(qreq_)
    SVER = ut.get_argflag('--sver')
    if SVER:
        print('+------------')
        print('SMK_DEBUG SVER? YES!')
        print('+------------')
        qaid2_chipmatch_SVER_ = pipeline.spatial_verification(qaid2_chipmatch_SMK, qreq_)
        qaid2_chipmatch = qaid2_chipmatch_SVER_
    else:
        print('+------------')
        print('SMK_DEBUG SVER? NO')
        print('+------------')
        qaid2_chipmatch = qaid2_chipmatch_SMK
    print('+------------')
    print('SMK_DEBUG DISPLAY RESULT')
    print('+------------')
    cm_list = convert_smkmatch_to_chipmatch(qaid2_chipmatch, qaid2_scores)
    #filt2_meta = {}
    #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, filt2_meta, qreq_)
    qaid2_qres_ = pipeline.chipmatch_to_resdict(qreq_, cm_list)
    #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, filt2_meta, qreq_)
    for count, (qaid, qres) in enumerate(six.iteritems(qaid2_qres_)):
        print('+================')
        #qres = qaid2_qres_[qaid]
        qres.show_top(ibs, fnum=count)
        for aid in qres.aid2_score.keys():
            smkscore = qaid2_scores[qaid][aid]
            sumscore = qres.aid2_score[aid]
            if not ut.almost_eq(smkscore, sumscore):
                print('scorediff aid=%r, smkscore=%r, sumscore=%r' % (aid, smkscore, sumscore))

        scores = qaid2_scores[qaid]
        #print(scores)
        print(qres.get_inspect_str(ibs))
        print('L================')
        #ut.embed()
    #print(qres.aid2_fs)
    #daid2_totalscore, cmtup_old = smk_index.query_inverted_index(annots_df, qaid, invindex)
    ## Pack into QueryResult
    #qaid2_chipmatch = {qaid: cmtup_old}
    #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, {}, qreq_)
    ## Show match
    #daid2_totalscore.sort(axis=1, ascending=False)
    #print(daid2_totalscore)

    #daid2_totalscore2, cmtup_old = query_inverted_index(annots_df, daids[0], invindex)
    #print(daid2_totalscore2)
    #display_info(ibs, invindex, annots_df)
    print('finished main')
    return locals()
Example #7
0
def main_smk_debug():
    """
    CommandLine:
        python -m ibeis.algo.hots.smk.smk_debug --test-main_smk_debug

    Example:
        >>> from ibeis.algo.hots.smk.smk_debug import *  # NOQA
        >>> main_smk_debug()
    """
    print('+------------')
    print('SMK_DEBUG MAIN')
    print('+------------')
    from ibeis.algo.hots import pipeline
    ibs, annots_df, taids, daids, qaids, qreq_, nWords = testdata_dataframe()
    # Query using SMK
    #qaid = qaids[0]
    nWords = qreq_.qparams.nWords
    aggregate = qreq_.qparams.aggregate
    smk_alpha = qreq_.qparams.smk_alpha
    smk_thresh = qreq_.qparams.smk_thresh
    nAssign = qreq_.qparams.nAssign
    #aggregate = ibs.cfg.query_cfg.smk_cfg.aggregate
    #smk_alpha = ibs.cfg.query_cfg.smk_cfg.smk_alpha
    #smk_thresh = ibs.cfg.query_cfg.smk_cfg.smk_thresh
    print('+------------')
    print('SMK_DEBUG PARAMS')
    print('[smk_debug] aggregate = %r' % (aggregate, ))
    print('[smk_debug] smk_alpha   = %r' % (smk_alpha, ))
    print('[smk_debug] smk_thresh  = %r' % (smk_thresh, ))
    print('[smk_debug] nWords  = %r' % (nWords, ))
    print('[smk_debug] nAssign = %r' % (nAssign, ))
    print('L------------')
    # Learn vocabulary
    #words = qreq_.words = smk_index.learn_visual_words(annots_df, taids, nWords)
    # Index a database of annotations
    #qreq_.invindex = smk_repr.index_data_annots(annots_df, daids, words, aggregate, smk_alpha, smk_thresh)
    qreq_.ibs = ibs
    # Smk Mach
    print('+------------')
    print('SMK_DEBUG MATCH KERNEL')
    print('+------------')
    qaid2_scores, qaid2_chipmatch_SMK = smk_match.execute_smk_L5(qreq_)
    SVER = ut.get_argflag('--sver')
    if SVER:
        print('+------------')
        print('SMK_DEBUG SVER? YES!')
        print('+------------')
        qaid2_chipmatch_SVER_ = pipeline.spatial_verification(
            qaid2_chipmatch_SMK, qreq_)
        qaid2_chipmatch = qaid2_chipmatch_SVER_
    else:
        print('+------------')
        print('SMK_DEBUG SVER? NO')
        print('+------------')
        qaid2_chipmatch = qaid2_chipmatch_SMK
    print('+------------')
    print('SMK_DEBUG DISPLAY RESULT')
    print('+------------')
    cm_list = convert_smkmatch_to_chipmatch(qaid2_chipmatch, qaid2_scores)
    #filt2_meta = {}
    #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, filt2_meta, qreq_)
    qaid2_qres_ = pipeline.chipmatch_to_resdict(qreq_, cm_list)
    #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, filt2_meta, qreq_)
    for count, (qaid, qres) in enumerate(six.iteritems(qaid2_qres_)):
        print('+================')
        #qres = qaid2_qres_[qaid]
        qres.show_top(ibs, fnum=count)
        for aid in qres.aid2_score.keys():
            smkscore = qaid2_scores[qaid][aid]
            sumscore = qres.aid2_score[aid]
            if not ut.almost_eq(smkscore, sumscore):
                print('scorediff aid=%r, smkscore=%r, sumscore=%r' %
                      (aid, smkscore, sumscore))

        scores = qaid2_scores[qaid]
        #print(scores)
        print(qres.get_inspect_str(ibs))
        print('L================')
        #ut.embed()
    #print(qres.aid2_fs)
    #daid2_totalscore, cmtup_old = smk_index.query_inverted_index(annots_df, qaid, invindex)
    ## Pack into QueryResult
    #qaid2_chipmatch = {qaid: cmtup_old}
    #qaid2_qres_ = pipeline.chipmatch_to_resdict(qaid2_chipmatch, {}, qreq_)
    ## Show match
    #daid2_totalscore.sort(axis=1, ascending=False)
    #print(daid2_totalscore)

    #daid2_totalscore2, cmtup_old = query_inverted_index(annots_df, daids[0], invindex)
    #print(daid2_totalscore2)
    #display_info(ibs, invindex, annots_df)
    print('finished main')
    return locals()