def update_query_cfg(ibs, **kwargs): r""" Updates query config only. Configs needs a restructure very badly DEPRICATE RESTful: Method: PUT URL: /api/query/cfg/ """ Config.update_query_config(ibs.cfg, **kwargs) ibs.reset_table_cache()
def _load_named_config(ibs, cfgname=None): r""" """ # TODO: update cfgs between versions # Try to load previous config otherwise default #use_config_cache = not (ut.is_developer() and not ut.get_argflag(('--nocache-pref',))) use_config_cache = not ut.get_argflag(('--nocache-pref',)) ibs.cfg = Config.load_named_config(cfgname, ibs.get_dbdir(), use_config_cache) ibs.reset_table_cache()
def _load_named_config(ibs, cfgname=None): r""" """ # TODO: update cfgs between versions # Try to load previous config otherwise default #use_config_cache = not (ut.is_developer() and not ut.get_argflag(('--nocache-pref',))) use_config_cache = not ut.get_argflag(('--nocache-pref', )) ibs.cfg = Config.load_named_config(cfgname, ibs.get_dbdir(), use_config_cache) ibs.reset_table_cache()
def get_varied_pipecfg_lbls(cfgdict_list, pipecfg_list=None): if pipecfg_list is None: from ibeis.algo import Config cfg_default_dict = dict(Config.QueryConfig().parse_items()) cfgx2_lbl = ut.get_varied_cfg_lbls(cfgdict_list, cfg_default_dict) else: # TODO: group cfgdict by config type and then get varied labels cfg_default_dict = None cfgx2_lbl = ut.get_varied_cfg_lbls(cfgdict_list, cfg_default_dict) return cfgx2_lbl
def hack_lnbnn_config_trail(qparams): query_cfg = Config.QueryConfig() lnbnn_trail = [ query_cfg.nn_cfg.asdict(), query_cfg.nnweight_cfg.asdict(), query_cfg.sv_cfg.asdict(), query_cfg.agg_cfg.asdict(), query_cfg.flann_cfg.asdict(), ] # Does not include feautres. Instead use # print(ut.repr3([c.asdict() for c in ibs.depc.get_config_trail('featweight', {})])) return lnbnn_trail
def _default_config(ibs, cfgname=None, new=True): r""" Resets the databases's algorithm configuration Args: ibs (IBEISController): ibeis controller object cfgname (None): CommandLine: python -m ibeis.control.manual_meta_funcs --test-_default_config Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.Config import * # NOQA >>> from ibeis.control.manual_meta_funcs import * # NOQA >>> import ibeis >>> # build test data >>> ibs = ibeis.opendb('testdb1') >>> assert not hasattr(ibs.cfg.query_cfg.flann_cfg, 'badparam') >>> ibs.cfg.query_cfg.flann_cfg.badparam = True >>> assert ibs.cfg.query_cfg.flann_cfg.cb_index == .4 >>> ibs.cfg.query_cfg.flann_cfg.cb_index = .5 >>> assert ibs.cfg.query_cfg.flann_cfg.cb_index == .5 >>> assert hasattr(ibs.cfg.query_cfg.flann_cfg, 'badparam') >>> # bad params is not initially removed but when you specify new it is >>> ibs._default_config(new=False) >>> assert ibs.cfg.query_cfg.flann_cfg.cb_index == .4 >>> assert hasattr(ibs.cfg.query_cfg.flann_cfg, 'badparam') >>> # bad param should be removed when config is defaulted >>> ibs._default_config(new=True) >>> assert not hasattr(ibs.cfg.query_cfg.flann_cfg, 'badparam') cfg = ibs.cfg """ #species_list = ibs.get_database_species() #if len(species_list) == 1: # # try to be intelligent about the default speceis # cfgname = species_list[0] ibs.cfg = Config._default_config(ibs.cfg, cfgname, new=new) ibs.reset_table_cache()
def __init__(qparams, query_cfg=None, cfgdict=None): """ Rename to pipeline params Structure to store static query pipeline parameters parses nested config structure into this flat one Args: query_cfg (QueryConfig): query_config cfgdict (dict or None): dictionary to update query_cfg with CommandLine: python -m ibeis.algo.hots.query_params --test-__init__ Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.hots.query_params import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb('testdb1') >>> query_cfg = ibs.cfg.query_cfg >>> #query_cfg.pipeline_root = 'asmk' >>> cfgdict = {'pipeline_root': 'asmk', 'sv_on': False, 'fg_on': True} >>> qparams = QueryParams(query_cfg, cfgdict) >>> assert qparams.pipeline_root == 'smk' >>> assert qparams.fg_on is True >>> result = qparams.query_cfgstr >>> print(')_\n'.join(result.split(')_'))) Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.hots.query_params import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb('testdb1') >>> query_cfg = ibs.cfg.query_cfg >>> #query_cfg.pipeline_root = 'asmk' >>> cfgdict = dict(rotation_invariance=True) >>> qparams = QueryParams(query_cfg, cfgdict) >>> ut.assert_eq(qparams.hesaff_params['rotation_invariance'], True) _smk_SMK(agg=True,t=0.0,a=3.0,idf)_ VocabAssign(nAssign=10,a=1.2,s=None,eqw=T)_ VocabTrain(nWords=8000,init=akmeans++,nIters=128,taids=all)_ SV(OFF)_ FEATWEIGHT(ON,uselabel,rf)_ FEAT(hesaff+sift_)_ CHIP(sz450) """ # if given custom settings update the config and ensure feasibilty if query_cfg is None: query_cfg = Config.QueryConfig() if cfgdict is not None: query_cfg = query_cfg.deepcopy() query_cfg.update_query_cfg(**cfgdict) # Get flat item list param_list = Config.parse_config_items(query_cfg) # Assert that there are no config conflicts duplicate_keys = ut.find_duplicate_items( ut.get_list_column(param_list, 0)) assert len(duplicate_keys ) == 0, 'Configs have duplicate names: %r' % duplicate_keys # Set nexted config attributes as flat qparam properties for key, val in param_list: setattr(qparams, key, val) # Add params not implicitly represented in Config object pipeline_root = query_cfg.pipeline_root qparams.chip_cfg_dict = query_cfg._featweight_cfg._feat_cfg._chip_cfg.to_dict( ) qparams.flann_params = query_cfg.flann_cfg.get_flann_params() qparams.hesaff_params = query_cfg._featweight_cfg._feat_cfg.get_hesaff_params( ) qparams.pipeline_root = pipeline_root qparams.vsmany = pipeline_root == 'vsmany' qparams.vsone = pipeline_root == 'vsone' # Add custom strings to the mix as well # TODO; Find better way to specify config strings # FIXME: probchip is not in here qparams.probchip_cfgstr = query_cfg._featweight_cfg.get_cfgstr( use_feat=False, use_chip=False) qparams.featweight_cfgstr = query_cfg._featweight_cfg.get_cfgstr() qparams.chip_cfgstr = query_cfg._featweight_cfg._feat_cfg._chip_cfg.get_cfgstr( ) qparams.feat_cfgstr = query_cfg._featweight_cfg._feat_cfg.get_cfgstr() qparams.nn_cfgstr = query_cfg.nn_cfg.get_cfgstr() qparams.nnweight_cfgstr = query_cfg.nnweight_cfg.get_cfgstr() qparams.sv_cfgstr = query_cfg.sv_cfg.get_cfgstr() qparams.flann_cfgstr = query_cfg.flann_cfg.get_cfgstr() qparams.query_cfgstr = query_cfg.get_cfgstr() qparams.vocabtrain_cfgstr = query_cfg.smk_cfg.vocabtrain_cfg.get_cfgstr( ) qparams.rrvsone_cfgstr = query_cfg.rrvsone_cfg.get_cfgstr()
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_
def devfunc(ibs, qaid_list): """ Function for developing something """ print('[dev] devfunc') import ibeis # NOQA from ibeis.algo import Config # NOQA #from ibeis.algo.Config import * # NOQA feat_cfg = Config.FeatureConfig() #feat_cfg.printme3() print('\ncfgstr..') print(feat_cfg.get_cfgstr()) print(utool.dict_str(feat_cfg.get_hesaff_params())) from ibeis import viz aid = 1 ibs.cfg.feat_cfg.threshold = 16.0 / 3.0 kpts = ibs.get_annot_kpts(aid) print('len(kpts) = %r' % len(kpts)) from ibeis.expt import experiment_configs #varyparams_list = [ # #{ # # 'threshold': [16.0 / 3.0, 32.0 / 3.0], # 8.0 / 3.0 # # 'numberOfScales': [3, 2, 1], # # 'maxIterations': [16, 32], # # 'convergenceThreshold': [.05, .1], # # 'initialSigma': [1.6, 1.2], # #}, # { # #'threshold': [16.0 / 3.0, 32.0 / 3.0], # 8.0 / 3.0 # 'numberOfScales': [1], # #'maxIterations': [16, 32], # #'convergenceThreshold': [.05, .1], # #'initialSigma': [6.0, 3.0, 2.0, 1.6, 1.2, 1.1], # 'initialSigma': [3.2, 1.6, 0.8], # 'edgeEigenValueRatio': [10, 5, 3], # }, #] varyparams_list = [experiment_configs.featparams] # low threshold = more keypoints # low initialSigma = more keypoints nKpts_list = [] cfgstr_list = [] alldictcomb = utool.flatten([ utool.util_dict.all_dict_combinations(varyparams) for varyparams in featparams_list ]) NUM_PASSES = 1 if not utool.get_argflag('--show') else 2 for count in range(NUM_PASSES): for aid in qaid_list: #for dict_ in utool.progiter(alldictcomb, lbl='feature param comb: ', total=len(alldictcomb)): for dict_ in alldictcomb: for key_, val_ in six.iteritems(dict_): ibs.cfg.feat_cfg[key_] = val_ cfgstr_ = ibs.cfg.feat_cfg.get_cfgstr() cfgstr = utool.packstr(cfgstr_, textwidth=80, breakchars=',', newline_prefix='', break_words=False, wordsep=',') if count == 0: kpts = ibs.get_annot_kpts(aid) #print('___________') #print('len(kpts) = %r' % len(kpts)) #print(cfgstr) nKpts_list.append(len(kpts)) cfgstr_list.append(cfgstr_) if count == 1: title_suffix = (' len(kpts) = %r \n' % len(kpts)) + cfgstr viz.show_chip(ibs, aid, fnum=pt.next_fnum(), title_suffix=title_suffix, darken=.4, ell_linewidth=2, ell_alpha=.8) if count == 0: nKpts_list = np.array(nKpts_list) cfgstr_list = np.array(cfgstr_list) print(get_sortbystr(cfgstr_list, nKpts_list, 'cfg', 'nKpts')) pt.present() locals_ = locals() return locals_
def __init__(qparams, query_cfg=None, cfgdict=None): """ Rename to pipeline params Structure to store static query pipeline parameters parses nested config structure into this flat one Args: query_cfg (QueryConfig): query_config cfgdict (dict or None): dictionary to update query_cfg with CommandLine: python -m ibeis.algo.hots.query_params --test-__init__ Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.hots.query_params import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb('testdb1') >>> query_cfg = ibs.cfg.query_cfg >>> #query_cfg.pipeline_root = 'asmk' >>> cfgdict = {'pipeline_root': 'asmk', 'sv_on': False, 'fg_on': True} >>> qparams = QueryParams(query_cfg, cfgdict) >>> assert qparams.pipeline_root == 'smk' >>> assert qparams.fg_on is True >>> result = qparams.query_cfgstr >>> print(')_\n'.join(result.split(')_'))) Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.hots.query_params import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb('testdb1') >>> query_cfg = ibs.cfg.query_cfg >>> #query_cfg.pipeline_root = 'asmk' >>> cfgdict = dict(rotation_invariance=True) >>> qparams = QueryParams(query_cfg, cfgdict) >>> ut.assert_eq(qparams.hesaff_params['rotation_invariance'], True) _smk_SMK(agg=True,t=0.0,a=3.0,idf)_ VocabAssign(nAssign=10,a=1.2,s=None,eqw=T)_ VocabTrain(nWords=8000,init=akmeans++,nIters=128,taids=all)_ SV(OFF)_ FEATWEIGHT(ON,uselabel,rf)_ FEAT(hesaff+sift_)_ CHIP(sz450) """ # if given custom settings update the config and ensure feasibilty if query_cfg is None: query_cfg = Config.QueryConfig() if cfgdict is not None: query_cfg = query_cfg.deepcopy() query_cfg.update_query_cfg(**cfgdict) # Get flat item list param_list = Config.parse_config_items(query_cfg) # Assert that there are no config conflicts duplicate_keys = ut.find_duplicate_items(ut.get_list_column(param_list, 0)) assert len(duplicate_keys) == 0, 'Configs have duplicate names: %r' % duplicate_keys # Set nexted config attributes as flat qparam properties for key, val in param_list: setattr(qparams, key, val) # Add params not implicitly represented in Config object pipeline_root = query_cfg.pipeline_root qparams.chip_cfg_dict = query_cfg._featweight_cfg._feat_cfg._chip_cfg.to_dict() qparams.flann_params = query_cfg.flann_cfg.get_flann_params() qparams.hesaff_params = query_cfg._featweight_cfg._feat_cfg.get_hesaff_params() qparams.pipeline_root = pipeline_root qparams.vsmany = pipeline_root == 'vsmany' qparams.vsone = pipeline_root == 'vsone' # Add custom strings to the mix as well # TODO; Find better way to specify config strings # FIXME: probchip is not in here qparams.probchip_cfgstr = query_cfg._featweight_cfg.get_cfgstr( use_feat=False, use_chip=False) qparams.featweight_cfgstr = query_cfg._featweight_cfg.get_cfgstr() qparams.chip_cfgstr = query_cfg._featweight_cfg._feat_cfg._chip_cfg.get_cfgstr() qparams.feat_cfgstr = query_cfg._featweight_cfg._feat_cfg.get_cfgstr() qparams.nn_cfgstr = query_cfg.nn_cfg.get_cfgstr() qparams.nnweight_cfgstr = query_cfg.nnweight_cfg.get_cfgstr() qparams.sv_cfgstr = query_cfg.sv_cfg.get_cfgstr() qparams.flann_cfgstr = query_cfg.flann_cfg.get_cfgstr() qparams.query_cfgstr = query_cfg.get_cfgstr() qparams.vocabtrain_cfgstr = query_cfg.smk_cfg.vocabtrain_cfg.get_cfgstr() qparams.rrvsone_cfgstr = query_cfg.rrvsone_cfg.get_cfgstr()