Exemple #1
0
def new_query_request(ibs,
                      qaid_list,
                      daid_list,
                      cfgdict=None,
                      verbose=ut.NOT_QUIET,
                      **kwargs):
    """
    alias for ibeis.algo.hots.query_request.new_ibeis_query_request

    Args:
        qaid_list (list):
        daid_list (list):
        cfgdict (None):
        verbose (bool):

    Returns:
        ibeis.QueryRequest: qreq_ -  hyper-parameters
    """
    from ibeis.algo.hots import query_request
    qreq_ = query_request.new_ibeis_query_request(ibs,
                                                  qaid_list,
                                                  daid_list,
                                                  cfgdict=cfgdict,
                                                  verbose=verbose,
                                                  **kwargs)
    return qreq_
Exemple #2
0
def testdata_ibeis2(cfgdict=None, **kwargs):
    """
    Step 2

    selects training and test set

    Example:
        >>> from ibeis.algo.hots.smk.smk_debug import *  # NOQA
        >>> kwargs = {}
    """
    from ibeis.algo.hots.smk import smk_debug
    print('[smk_debug] testdata_ibeis2')
    ibs = smk_debug.testdata_ibeis(**kwargs)
    valid_aids = ibs.get_valid_aids()
    # Training/Database/Search set
    taids = valid_aids[:]
    daids  = valid_aids
    #daids = valid_aids[1:10]
    #daids = valid_aids[0:3]
    #qaids = valid_aids[0::2]
    #qaids = valid_aids[0:2]
    #qaids = [37]  # NOQA new test case for PZ_MTEST
    #qaids = [valid_aids[0], valid_aids[4]]
    qaids = [valid_aids[0]]
    # FIXME: can't set to a list right now
    cfgdict = {
        'vocab_taids': 'all',
    }
    if cfgdict is not None:
        cfgdict.update(cfgdict)
    qreq_ = query_request.new_ibeis_query_request(ibs, qaids, daids, cfgdict)
    qreq_.ibs = ibs  # Hack
    return ibs, taids, daids, qaids, qreq_
Exemple #3
0
def testdata_ibeis2(cfgdict=None, **kwargs):
    """
    Step 2

    selects training and test set

    Example:
        >>> from ibeis.algo.hots.smk.smk_debug import *  # NOQA
        >>> kwargs = {}
    """
    from ibeis.algo.hots.smk import smk_debug
    print('[smk_debug] testdata_ibeis2')
    ibs = smk_debug.testdata_ibeis(**kwargs)
    valid_aids = ibs.get_valid_aids()
    # Training/Database/Search set
    taids = valid_aids[:]
    daids = valid_aids
    #daids = valid_aids[1:10]
    #daids = valid_aids[0:3]
    #qaids = valid_aids[0::2]
    #qaids = valid_aids[0:2]
    #qaids = [37]  # NOQA new test case for PZ_MTEST
    #qaids = [valid_aids[0], valid_aids[4]]
    qaids = [valid_aids[0]]
    # FIXME: can't set to a list right now
    cfgdict = {
        'vocab_taids': 'all',
    }
    if cfgdict is not None:
        cfgdict.update(cfgdict)
    qreq_ = query_request.new_ibeis_query_request(ibs, qaids, daids, cfgdict)
    qreq_.ibs = ibs  # Hack
    return ibs, taids, daids, qaids, qreq_
Exemple #4
0
def test_windex():
    from ibeis.algo.hots.query_request import new_ibeis_query_request
    import ibeis
    daid_list = [7, 8, 9, 10, 11]
    ibs = ibeis.opendb(db='testdb1')
    qreq_ = new_ibeis_query_request(ibs, daid_list, daid_list)
    windex = new_ibeis_windex(ibs, qreq_.get_internal_daids())
    return windex, qreq_, ibs
Exemple #5
0
def test_windex():
    from ibeis.algo.hots.query_request import new_ibeis_query_request
    import ibeis
    daid_list = [7, 8, 9, 10, 11]
    ibs = ibeis.opendb(db='testdb1')
    qreq_ = new_ibeis_query_request(ibs, daid_list, daid_list)
    windex = new_ibeis_windex(ibs, qreq_.get_internal_daids())
    return windex, qreq_, ibs
Exemple #6
0
def train_baseline_ibeis_normalizer(ibs, use_cache=True, **learnkw):
    r"""
    Runs unnormalized queries to compute normalized queries

    Args:
        ibs (IBEISController):

    Returns:
        ScoreNormalizer: encoder

    CommandLine:
        python -m ibeis.algo.hots.score_normalization --test-train_baseline_ibeis_normalizer --cmd
        python -m ibeis.algo.hots.score_normalization --test-train_baseline_ibeis_normalizer --noshow

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.score_normalization import *  # NOQA
        >>> from ibeis.all_imports import *  # NOQA
        >>> import plottool as pt
        >>> import ibeis
        >>> from ibeis.algo.hots import score_normalization
        >>> #score_normalization.rrr()
        >>> dbname = 'GZ_ALL'
        >>> dbname = 'PZ_MTEST'
        >>> ibs = ibeis.opendb(dbname)
        >>> learnkw = dict()
        >>> encoder = score_normalization.train_baseline_ibeis_normalizer(ibs, use_cache=False, **learnkw)
        >>> encoder.visualize()
        >>> result = str(encoder)
        >>> print(result)
        >>> exec(pt.present())
    """
    from ibeis.algo.hots import query_request
    # TRAIN BASELINE
    tag = '<TRAINING> '
    print(utool.msgblock(tag, 'Begning Training'))
    with utool.Timer(tag):
        #with utool.Indenter('TRAIN >>> '):
        qaid_list = ibs.get_valid_aids()
        daid_list = ibs.get_valid_aids()
        #cfgdict = dict(codename='nsum_unnorm')
        codename = 'vsone_unnorm'
        cfgdict = dict(codename=codename)
        qreq_ = query_request.new_ibeis_query_request(ibs, qaid_list, daid_list, cfgdict)
        use_qcache = True
        cm_list = ibs.query_chips(qaid_list, daid_list, qreq_=qreq_, use_cache=use_qcache, return_cm=True)
        encoder = cached_annotscore_normer(cm_list, qreq_,
                                                   use_cache=use_cache,
                                                   **learnkw)
        # Save as baseline for this species
        species_text = '_'.join(qreq_.get_unique_species())  # HACK
        baseline_cfgstr = 'baseline_' + species_text
        cachedir = ibs.get_global_species_scorenorm_cachedir(species_text)
        encoder.save(cachedir, cfgstr=baseline_cfgstr)
    print('\n' + utool.msgblock(tag, 'Finished Training'))
    return encoder
def new_query_request(ibs,
                      qaid_list,
                      daid_list,
                      cfgdict=None,
                      verbose=ut.NOT_QUIET,
                      **kwargs):
    """
    alias for ibeis.algo.hots.query_request.new_ibeis_query_request

    Args:
        qaid_list (list):
        daid_list (list):
        cfgdict (None):
        verbose (bool):

    Returns:
        QueryRequest: qreq_ -  hyper-parameters

    CommandLine:
        python -m ibeis.control.manual_ibeiscontrol_funcs --test-new_query_request

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.control.manual_ibeiscontrol_funcs import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> daid_list = ibs.get_valid_aids()
        >>> qaid_list = daid_list[0:2]
        >>> cfgdict = {}
        >>> verbose = True
        >>> qreq_ = new_query_request(ibs, qaid_list, daid_list, cfgdict, verbose)
        >>> qreq_.set_external_qaid_mask(qaid_list[1:2])
        >>> print(qreq_.get_external_qaids())
        >>> result = str(qreq_.get_query_hashid())
        >>> print(result)
        _QSUUIDS((1)nozvwbdokngephfk)

        _QSUUIDS((1)nztoqb6&7apjltd1)
    """
    from ibeis.algo.hots import query_request
    qreq_ = query_request.new_ibeis_query_request(ibs,
                                                  qaid_list,
                                                  daid_list,
                                                  cfgdict=cfgdict,
                                                  verbose=verbose,
                                                  **kwargs)
    return qreq_
Exemple #8
0
def _compute_svvars(ibs, aid1):
    """ If spatial-verfication dbginfo is not in we need to compute it """
    from ibeis.algo.hots import _pipeline_helpers as plh
    from ibeis.algo.hots import query_request
    daids = ibs.get_valid_aids()
    qaids = [aid1]
    cfgdict = dict(with_metadata=True)
    qreq_ = query_request.new_ibeis_query_request(ibs, qaids, daids, cfgdict)
    assert len(daids) > 0, '!!! nothing to search'
    assert len(qaids) > 0, '!!! nothing to query'
    qreq_.lazy_load()
    pipeline_locals_ = plh.testrun_pipeline_upto(qreq_, None)
    qaid2_chipmatch_FILT = pipeline_locals_['qaid2_chipmatch_FILT']
    qaid2_svtups         = qreq_.metadata['qaid2_svtups']
    chipmatch_FILT = qaid2_chipmatch_FILT[aid1]
    aid2_svtup     = qaid2_svtups[aid1]
    return chipmatch_FILT, aid2_svtup
def new_query_request(ibs, qaid_list, daid_list, cfgdict=None,
                      verbose=ut.NOT_QUIET, **kwargs):
    """
    alias for ibeis.algo.hots.query_request.new_ibeis_query_request

    Args:
        qaid_list (list):
        daid_list (list):
        cfgdict (None):
        verbose (bool):

    Returns:
        QueryRequest: qreq_ -  hyper-parameters

    CommandLine:
        python -m ibeis.control.manual_ibeiscontrol_funcs --test-new_query_request

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.control.manual_ibeiscontrol_funcs import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> daid_list = ibs.get_valid_aids()
        >>> qaid_list = daid_list[0:2]
        >>> cfgdict = {}
        >>> verbose = True
        >>> qreq_ = new_query_request(ibs, qaid_list, daid_list, cfgdict, verbose)
        >>> qreq_.set_external_qaid_mask(qaid_list[1:2])
        >>> print(qreq_.get_external_qaids())
        >>> result = str(qreq_.get_query_hashid())
        >>> print(result)
        _QSUUIDS((1)a5boe72@61xjfpo%)

        _QSUUIDS((1)nztoqb6&7apjltd1)
    """
    from ibeis.algo.hots import query_request
    qreq_ = query_request.new_ibeis_query_request(
        ibs, qaid_list, daid_list, cfgdict=cfgdict, verbose=verbose, **kwargs)
    return qreq_
Exemple #10
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()
Exemple #11
0
def get_pipeline_testdata(dbname=None,
                          cfgdict=None,
                          qaid_list=None,
                          daid_list=None,
                          defaultdb='testdb1',
                          cmdline_ok=True,
                          preload=True):
    r"""
    Gets testdata for pipeline defined by tests / and or command line

    DEPRICATE in favor of ibeis.init.main_helpers.testdata_qreq

    Args:
        cmdline_ok : if false does not check command line

    Returns:
        tuple: ibs, qreq_

    CommandLine:
        python -m ibeis.algo.hots._pipeline_helpers --test-get_pipeline_testdata
        python -m ibeis.algo.hots._pipeline_helpers --test-get_pipeline_testdata --daid_list 39 --qaid 41 --db PZ_MTEST
        python -m ibeis.algo.hots._pipeline_helpers --test-get_pipeline_testdata --daids 39 --qaid 41 --db PZ_MTEST
        python -m ibeis.algo.hots._pipeline_helpers --test-get_pipeline_testdata --qaid 41 --db PZ_MTEST
        python -m ibeis.algo.hots._pipeline_helpers --test-get_pipeline_testdata --controlled_daids --qaids=41 --db PZ_MTEST --verb-testdata

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.algo.hots._pipeline_helpers import *
        >>> import ibeis  # NOQA
        >>> from ibeis.algo.hots import _pipeline_helpers as plh
        >>> cfgdict = dict(pipeline_root='vsone', codename='vsone')
        >>> ibs, qreq_ = plh.get_pipeline_testdata(cfgdict=cfgdict)
        >>> result = ''
        >>> result += ('daids = %r\n' % (qreq_.get_external_daids(),))
        >>> result += ('qaids = %r' % (qreq_.get_external_qaids(),))
        >>> print('cfgstr %s'  % (qreq_.qparams.query_cfgstr,))
        >>> print(result)

        daids = array([1, 2, 3, 4, 5])
        qaids = array([1])
    """
    import ibeis
    from ibeis.algo.hots import query_request
    # Allow commandline specification if paramaters are not specified in tests
    if cfgdict is None:
        cfgdict = {}

    assert cmdline_ok is True, 'cmdline_ok should always be True'

    if cmdline_ok:
        from ibeis.algo import Config
        # Allow specification of db and qaids/daids
        if dbname is not None:
            defaultdb = dbname
        dbname = ut.get_argval('--db', type_=str, default=defaultdb)

    ibs = ibeis.opendb(defaultdb=dbname)

    default_qaid_list = qaid_list
    default_daid_list = daid_list

    # setup special defautls

    if default_qaid_list is None:
        default_qaid_list = {
            'testdb1' : [1],
            'GZ_ALL'  : [1032],
            'PZ_ALL'  : [1, 3, 5, 9],
        }.get(dbname, [1])

    default_daid_list = ut.get_argval(('--daids', '--daid-list'), type_=list, default=default_daid_list)

    if default_daid_list is None:
        if dbname == 'testdb1':
            default_daid_list = ibs.get_valid_aids()[0:5]
        else:
            default_daid_list = 'all'

    # Use commmand line parsing for custom values

    if cmdline_ok:
        from ibeis.init import main_helpers
        qaid_list_ = main_helpers.get_test_qaids(ibs, default_qaids=default_qaid_list)
        daid_list_ = main_helpers.get_test_daids(ibs, default_daids=default_daid_list, qaid_list=qaid_list_)
        #
        # Allow commond line specification of all query params
        default_cfgdict = dict(Config.parse_config_items(Config.QueryConfig()))
        default_cfgdict.update(cfgdict)
        _orig_cfgdict = cfgdict
        force_keys = set(list(_orig_cfgdict.keys()))
        cfgdict_ = ut.util_arg.argparse_dict(
            default_cfgdict, verbose=not ut.QUIET, only_specified=True,
            force_keys=force_keys)
        #ut.embed()
        if VERB_PIPELINE or VERB_TESTDATA:
            print('[plh] cfgdict_ = ' + ut.dict_str(cfgdict_))
    else:
        qaid_list_ = qaid_list
        daid_list_ = daid_list
        cfgdict_ = cfgdict

    #ibs = ibeis.test_main(db=dbname)

    if VERB_TESTDATA:
        #ibeis.other.dbinfo.print_qd_info(ibs, qaid_list_, daid_list_, verbose=True)
        ibeis.other.dbinfo.print_qd_info(ibs, qaid_list_, daid_list_, verbose=False)

    if 'with_metadata' not in cfgdict:
        cfgdict_['with_metadata'] = True
    qreq_ = query_request.new_ibeis_query_request(ibs, qaid_list_, daid_list_, cfgdict=cfgdict_)
    if preload:
        qreq_.lazy_load()
    return ibs, qreq_