def customize_base_cfg( cfgname, cfgopt_strs, base_cfg, cfgtype, alias_keys=None, valid_keys=None, offset=0, strict=True, ): """ DEPRICATE """ import re cfg = base_cfg.copy() # Parse dict out of a string # ANYTHING_NOT_BRACE = r'[^\[\]]*\]' ANYTHING_NOT_PAREN_OR_BRACE = r'[^()\[\]]*[\]\)]' cfgstr_options_list = re.split( r',\s*' + ut.negative_lookahead(ANYTHING_NOT_PAREN_OR_BRACE), cfgopt_strs ) # cfgstr_options_list = cfgopt_strs.split(',') cfg_options = ut.parse_cfgstr_list( cfgstr_list=cfgstr_options_list, smartcast=True, oldmode=False ) # Hack for q/d-prefix specific configs remove_prefix_hack(cfg, cfgtype, cfg_options, alias_keys) # Remap keynames based on aliases if alias_keys is not None: # Use new standard keys and remove old aliased keys for key in set(alias_keys.keys()): if key in cfg_options: cfg_options[alias_keys[key]] = cfg_options[key] del cfg_options[key] # Ensure that nothing bad is being updated if strict: parsed_keys = cfg_options.keys() if valid_keys is not None: ut.assert_all_in(parsed_keys, valid_keys, 'keys specified not in valid set') else: ut.assert_all_in( parsed_keys, cfg.keys(), 'keys specified not in default options' ) # Finalize configuration dict cfg.update(cfg_options) cfg['_cfgtype'] = cfgtype cfg['_cfgname'] = cfgname cfg_combo = ut.all_dict_combinations(cfg) # if len(cfg_combo) > 1: for combox, cfg_ in enumerate(cfg_combo, start=offset): # cfg_['_cfgname'] += ';' + str(combox) cfg_['_cfgindex'] = combox for cfg_ in cfg_combo: if len(cfgopt_strs) > 0: cfg_['_cfgstr'] = cfg_['_cfgname'] + ut.NAMEVARSEP + cfgopt_strs else: cfg_['_cfgstr'] = cfg_['_cfgname'] return cfg_combo
def customize_base_cfg(cfgname, cfgopt_strs, base_cfg, cfgtype, alias_keys=None, valid_keys=None, offset=0, strict=True): """ DEPRICATE """ import re cfg = base_cfg.copy() # Parse dict out of a string #ANYTHING_NOT_BRACE = r'[^\[\]]*\]' ANYTHING_NOT_PAREN_OR_BRACE = r'[^()\[\]]*[\]\)]' cfgstr_options_list = re.split( r',\s*' + ut.negative_lookahead(ANYTHING_NOT_PAREN_OR_BRACE), cfgopt_strs) #cfgstr_options_list = cfgopt_strs.split(',') cfg_options = ut.parse_cfgstr_list( cfgstr_list=cfgstr_options_list, smartcast=True, oldmode=False) # Hack for q/d-prefix specific configs remove_prefix_hack(cfg, cfgtype, cfg_options, alias_keys) # Remap keynames based on aliases if alias_keys is not None: # Use new standard keys and remove old aliased keys for key in set(alias_keys.keys()): if key in cfg_options: cfg_options[alias_keys[key]] = cfg_options[key] del cfg_options[key] # Ensure that nothing bad is being updated if strict: parsed_keys = cfg_options.keys() if valid_keys is not None: ut.assert_all_in(parsed_keys, valid_keys, 'keys specified not in valid set') else: ut.assert_all_in(parsed_keys, cfg.keys(), 'keys specified not in default options') # Finalize configuration dict cfg.update(cfg_options) cfg['_cfgtype'] = cfgtype cfg['_cfgname'] = cfgname cfg_combo = ut.all_dict_combinations(cfg) #if len(cfg_combo) > 1: for combox, cfg_ in enumerate(cfg_combo, start=offset): #cfg_['_cfgname'] += ';' + str(combox) cfg_['_cfgindex'] = combox for cfg_ in cfg_combo: if len(cfgopt_strs) > 0: cfg_['_cfgstr'] = cfg_['_cfgname'] + ut.NAMEVARSEP + cfgopt_strs else: cfg_['_cfgstr'] = cfg_['_cfgname'] return cfg_combo
def parse_cfgstr_list2(cfgstr_list, named_dcfgs_dict, cfgtype=None, alias_keys=None): """ Parse a genetic cfgstr --flag name1:custom_args1 name2:custom_args2 """ cfg_list = [] for cfgstr in cfgstr_list: cfgstr_split = cfgstr.split(':') cfgname = cfgstr_split[0] cfg = named_dcfgs_dict[cfgname].copy() # Parse dict out of a string if len(cfgstr_split) > 1: cfgstr_options = ':'.join(cfgstr_split[1:]).split(',') cfg_options = ut.parse_cfgstr_list(cfgstr_options, smartcast=True, oldmode=False) else: cfg_options = {} # Hack for q/d specific configs if cfgtype is not None: for key in list(cfg_options.keys()): # check if key is nonstandard if not (key in cfg or key in alias_keys): # does removing prefix make it stanard? prefix = cfgtype[0] if key.startswith(prefix): key_ = key[len(prefix):] if key_ in cfg or key_ in alias_keys: # remove prefix cfg_options[key_] = cfg_options[key] try: assert key[1:] in cfg or key[1:] in alias_keys, 'key=%r, key[1:] =%r' % (key, key[1:] ) except AssertionError as ex: ut.printex(ex, 'error', keys=['key', 'cfg', 'alias_keys']) raise del cfg_options[key] # Remap keynames based on aliases if alias_keys is not None: for key in alias_keys.keys(): if key in cfg_options: # use standard new key cfg_options[alias_keys[key]] = cfg_options[key] # remove old alised key del cfg_options[key] # Finalize configuration dict cfg = ut.update_existing(cfg, cfg_options, copy=True, assert_exists=True) cfg['_cfgtype'] = cfgtype cfg['_cfgname'] = cfgname cfg['_cfgstr'] = cfgstr cfg_list.append((cfgname, cfg)) break # FIXME: do more than one eventually return cfg
def postload_commands(ibs, back): """ Postload commands deal with a specific ibeis database ibeis --db PZ_MTEST --occur "*All Images" --query 1 ibeis --db PZ_MTEST --occur "*All Images" --query-intra """ if ut.NOT_QUIET: print('\n[main_cmd] postload_commands') if params.args.view_database_directory: print('got arg --vdd') vdd(ibs) if params.args.set_default_dbdir: sysres.set_default_dbdir(ibs.get_dbdir()) if params.args.update_query_cfg is not None: # Set query parameters from command line using the --cfg flag cfgdict = ut.parse_cfgstr_list(params.args.update_query_cfg) print('Custom cfgdict specified') print(ut.repr2(cfgdict)) ibs.update_query_cfg(**cfgdict) if params.args.edit_notes: ut.editfile(ibs.get_dbnotes_fpath(ensure=True)) if params.args.delete_cache: ibs.delete_cache() if params.args.delete_cache_complete: ibs.delete_cache(delete_imagesets=True) if params.args.delete_query_cache: ibs.delete_qres_cache() if params.args.set_all_species is not None: ibs._overwrite_all_annot_species_to(params.args.set_all_species) if params.args.dump_schema: ibs.db.print_schema() if ut.get_argflag('--ipynb'): back.launch_ipy_notebook() select_imgsetid = ut.get_argval(('--select-imgsetid', '--imgsetid', '--occur', '--gsid'), None) if select_imgsetid is not None: print('\n+ --- CMD SELECT IMGSETID=%r ---' % (select_imgsetid,)) # Whoa: this doesnt work. weird. #back.select_imgsetid(select_imgsetid) # This might be the root of gui problems #back.front._change_imageset(select_imgsetid) back.front.select_imageset_tab(select_imgsetid) print('L ___ CMD SELECT IMGSETID=%r ___\n' % (select_imgsetid,)) # Send commands to GUIBack if params.args.select_aid is not None: if back is not None: try: ibsfuncs.assert_valid_aids(ibs, (params.args.select_aid,)) except AssertionError: print('Valid RIDs are: %r' % (ibs.get_valid_aids(),)) raise back.select_aid(params.args.select_aid) if params.args.select_gid is not None: back.select_gid(params.args.select_gid) if params.args.select_nid is not None: back.select_nid(params.args.select_nid) select_name = ut.get_argval('--select-name') if select_name is not None: import ibeis.gui.guiheaders as gh back.ibswgt.select_table_indicies_from_text(gh.NAMES_TREE, select_name, allow_table_change=True) if ut.get_argflag(('--intra-occur-query', '--query-intra-occur', '--query-intra')): back.special_query_funcs['intra_occurrence'](cfgdict={'use_k_padding': False}) qaid_list = ut.get_argval(('--query-aid', '--query'), type_=list, default=None) if qaid_list is not None: #qaid_list = params.args.query_aid # fix stride case if len(qaid_list) == 1 and isinstance(qaid_list[0], tuple): qaid_list = list(qaid_list[0]) daids_mode = ut.get_argval('--daids-mode', type_=str, default=const.VS_EXEMPLARS_KEY) back.compute_queries(qaid_list=qaid_list, daids_mode=daids_mode, ranks_top=10) if ut.get_argflag('--inc-query'): back.incremental_query() if ut.get_argflag(('--dbinfo', '--display_dbinfo')): back.display_dbinfo() pass aidcmd = ut.get_argval('--aidcmd', default=None) aid = ut.get_argval('--aid', type_=int, default=1) if aidcmd: #aidcmd = 'Interact image' metadata = ibs.get_annot_lazy_dict(aid) annot_context_options = metadata['annot_context_options'] aidcmd_dict = dict(annot_context_options) print('aidcmd_dict = %s' % (ut.repr3(aidcmd_dict),)) command = aidcmd_dict[aidcmd] command() #import utool #utool.embed() #back.start_web_server_parallel() if ut.get_argflag('--start-web'): back.start_web_server_parallel() if ut.get_argflag('--name-tab'): from ibeis.gui.guiheaders import NAMES_TREE back.front.set_table_tab(NAMES_TREE) view = back.front.views[NAMES_TREE] model = view.model() view._set_sort(model.col_name_list.index('nAids'), col_sort_reverse=True) if ut.get_argflag('--graph'): back.make_qt_graph_interface() screengrab_fpath = ut.get_argval('--screengrab') if screengrab_fpath: from guitool.__PYQT__.QtGui import QPixmap from PyQt4.QtTest import QTest from PyQt4.QtCore import Qt fpath = ut.truepath(screengrab_fpath) import guitool #ut.embed() timer2 = guitool.__PYQT__.QtCore.QTimer() done = [1000] def delayed_screenshot_func(): if done[0] == 500: #back.mainwin.menubar.triggered.emit(back.mainwin.menuFile) print('Mouseclick') QTest.mouseClick(back.mainwin.menuFile, Qt.LeftButton) # This works #QTest.mouseClick(back.front.import_button, Qt.LeftButton) if done[0] == 1: timer2.stop() print('screengrab to %r' % (fpath,)) screenimg = QPixmap.grabWindow(back.mainwin.winId()) screenimg.save(fpath, 'jpg') ut.startfile(fpath) print('lub dub2') done[0] -= 1 return None CLICK_FILE_MENU = True if CLICK_FILE_MENU: #ut.embed() #QTest::keyClick(menu, Qt::Key_Down) pass timer2.delayed_screenshot_func = delayed_screenshot_func timer2.timeout.connect(timer2.delayed_screenshot_func) timer2.start(1) back.mainwin.timer2 = timer2 guitool.activate_qwindow(back.mainwin) #QPixmap.grabWindow(back.mainwin.winId()).save(fpath, 'jpg') #ut.startfile(fpath) #ut.embed() pass if params.args.postload_exit: print('[main_cmd] postload exit') sys.exit(0)
def get_pipecfg_list(test_cfg_name_list, ibs=None): r""" Builds a list of varied query configurations. Only custom configs depend on an ibs object. The order of the output is not gaurenteed to aggree with input order. Args: test_cfg_name_list (list): list of strs ibs (IBEISController): ibeis controller object (optional) Returns: tuple: (cfg_list, cfgx2_lbl) - cfg_list (list): list of config objects cfgx2_lbl (list): denotes which parameters are being varied. If there is just one config then nothing is varied CommandLine: python -m ibeis.expt.experiment_helpers --exec-get_pipecfg_list:0 python -m ibeis.expt.experiment_helpers --exec-get_pipecfg_list:1 --db humpbacks Example: >>> # ENABLE_DOCTEST >>> from ibeis.expt.experiment_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='testdb1') >>> #test_cfg_name_list = ['best', 'custom', 'custom:sv_on=False'] >>> #test_cfg_name_list = ['default', 'default:sv_on=False', 'best'] >>> test_cfg_name_list = ['default', 'default:sv_on=False', 'best'] >>> # execute function >>> (pcfgdict_list, pipecfg_list) = get_pipecfg_list(test_cfg_name_list, ibs) >>> # verify results >>> assert pipecfg_list[0].sv_cfg.sv_on is True >>> assert pipecfg_list[1].sv_cfg.sv_on is False >>> pipecfg_lbls = get_varied_pipecfg_lbls(pcfgdict_list) >>> result = ('pipecfg_lbls = '+ ut.list_str(pipecfg_lbls)) >>> print(result) pipecfg_lbls = [ 'default:', 'default:sv_on=False', ] Example1: >>> # DISABLE_DOCTEST >>> import ibeis_flukematch.plugin >>> from ibeis.expt.experiment_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='humpbacks') >>> test_cfg_name_list = ['default:pipeline_root=BC_DTW,decision=average', 'default:K=[1,4]'] >>> (pcfgdict_list, pipecfg_list) = get_pipecfg_list(test_cfg_name_list, ibs) >>> pipecfg_lbls = get_varied_pipecfg_lbls(pcfgdict_list) >>> result = ('pipecfg_lbls = '+ ut.list_str(pipecfg_lbls)) >>> print(result) >>> print_pipe_configs(pcfgdict_list, pipecfg_list) """ if ut.VERBOSE: print('[expt_help.get_pipecfg_list] building pipecfg_list using: %s' % test_cfg_name_list) if isinstance(test_cfg_name_list, six.string_types): test_cfg_name_list = [test_cfg_name_list] _standard_cfg_names = [] _pcfgdict_list = [] # HACK: Parse out custom configs first for test_cfg_name in test_cfg_name_list: if test_cfg_name.startswith('custom:') or test_cfg_name == 'custom': print('[expthelpers] Parsing nonstandard custom config') if test_cfg_name.startswith('custom:'): # parse out modifications to custom cfgstr_list = ':'.join(test_cfg_name.split(':')[1:]).split(',') augcfgdict = ut.parse_cfgstr_list(cfgstr_list, smartcast=True) else: augcfgdict = {} # Take the configuration from the ibeis object pipe_cfg = ibs.cfg.query_cfg.deepcopy() # Update with augmented params pipe_cfg.update_query_cfg(**augcfgdict) # Parse out a standard cfgdict cfgdict = dict(pipe_cfg.parse_items()) cfgdict['_cfgname'] = 'custom' cfgdict['_cfgstr'] = test_cfg_name _pcfgdict_list.append(cfgdict) else: _standard_cfg_names.append(test_cfg_name) # Handle stanndard configs next if len(_standard_cfg_names) > 0: # Get parsing information #cfg_default_dict = dict(Config.QueryConfig().parse_items()) #valid_keys = list(cfg_default_dict.keys()) cfgstr_list = _standard_cfg_names named_defaults_dict = ut.dict_subset( experiment_configs.__dict__, experiment_configs.TEST_NAMES) alias_keys = experiment_configs.ALIAS_KEYS # Parse standard pipeline cfgstrings metadata = {'ibs': ibs} dict_comb_list = cfghelpers.parse_cfgstr_list2( cfgstr_list, named_defaults_dict, cfgtype=None, alias_keys=alias_keys, # Hack out valid keys for humpbacks #valid_keys=valid_keys, strict=False, metadata=metadata ) # Get varied params (there may be duplicates) _pcfgdict_list.extend(ut.flatten(dict_comb_list)) # TODO: respsect different algorithm parameters # like flukes # Expand cfgdicts into PipelineConfig config objects if ibs is None: configclass_list = [Config.QueryConfig] * len(_pcfgdict_list) else: root_to_config = ibs.depc.configclass_dict configclass_list = [ root_to_config.get(_cfgdict.get('pipeline_root', 'vsmany'), Config.QueryConfig) for _cfgdict in _pcfgdict_list] _pipecfg_list = [cls(**_cfgdict) for cls, _cfgdict in zip(configclass_list, _pcfgdict_list)] # Enforce rule that removes duplicate configs # by using feasiblity from ibeis.algo.Config # TODO: Move this unique finding code to its own function # and then move it up one function level so even the custom # configs can be uniquified _flag_list = ut.flag_unique_items(_pipecfg_list) cfgdict_list = ut.compress(_pcfgdict_list, _flag_list) pipecfg_list = ut.compress(_pipecfg_list, _flag_list) if ut.NOT_QUIET: print('[harn.help] return %d / %d unique pipeline configs from: %r' % (len(cfgdict_list), len(_pcfgdict_list), test_cfg_name_list)) if ut.get_argflag(('--pcfginfo', '--pinfo', '--pipecfginfo')): import sys ut.colorprint('Requested PcfgInfo for tests... ', 'red') print_pipe_configs(cfgdict_list, pipecfg_list) ut.colorprint('Finished Reporting PcfgInfo. Exiting', 'red') sys.exit(1) return (cfgdict_list, pipecfg_list)
def postload_commands(ibs, back): """ Postload commands deal with a specific wbia database wbia --db PZ_MTEST --occur "*All Images" --query 1 wbia --db PZ_MTEST --occur "*All Images" --query-intra """ params.parse_args() if ut.NOT_QUIET: logger.info('\n[main_cmd] postload_commands') if params.args.view_database_directory: logger.info('got arg --vdd') vdd(ibs) if params.args.set_default_dbdir: sysres.set_default_dbdir(ibs.get_dbdir()) if params.args.update_query_cfg is not None: # Set query parameters from command line using the --cfg flag cfgdict = ut.parse_cfgstr_list(params.args.update_query_cfg) logger.info('Custom cfgdict specified') logger.info(ut.repr2(cfgdict)) ibs.update_query_cfg(**cfgdict) if params.args.edit_notes: ut.editfile(ibs.get_dbnotes_fpath(ensure=True)) if params.args.delete_cache: ibs.delete_cache() if params.args.delete_cache_complete: ibs.delete_cache(delete_imagesets=True) if params.args.delete_query_cache: ibs.delete_qres_cache() if params.args.set_all_species is not None: ibs._overwrite_all_annot_species_to(params.args.set_all_species) if params.args.dump_schema: ibs.db.print_schema() if ut.get_argflag('--ipynb'): back.launch_ipy_notebook() select_imgsetid = ut.get_argval( ('--select-imgsetid', '--imgsetid', '--occur', '--gsid'), None) if select_imgsetid is not None: logger.info('\n+ --- CMD SELECT IMGSETID=%r ---' % (select_imgsetid, )) # Whoa: this doesnt work. weird. # back.select_imgsetid(select_imgsetid) # This might be the root of gui problems # back.front._change_imageset(select_imgsetid) back.front.select_imageset_tab(select_imgsetid) logger.info('L ___ CMD SELECT IMGSETID=%r ___\n' % (select_imgsetid, )) # Send commands to GUIBack if params.args.select_aid is not None: if back is not None: try: ibsfuncs.assert_valid_aids(ibs, (params.args.select_aid, )) except AssertionError: logger.info('Valid RIDs are: %r' % (ibs.get_valid_aids(), )) raise back.select_aid(params.args.select_aid) if params.args.select_gid is not None: back.select_gid(params.args.select_gid) if params.args.select_nid is not None: back.select_nid(params.args.select_nid) select_name = ut.get_argval('--select-name') if select_name is not None: import wbia.gui.guiheaders as gh back.ibswgt.select_table_indicies_from_text(gh.NAMES_TREE, select_name, allow_table_change=True) if ut.get_argflag( ('--intra-occur-query', '--query-intra-occur', '--query-intra')): back.special_query_funcs['intra_occurrence'](cfgdict={ 'use_k_padding': False }) qaid_list = ut.get_argval(('--query-aid', '--query'), type_=list, default=None) if qaid_list is not None: # qaid_list = params.args.query_aid # fix stride case if len(qaid_list) == 1 and isinstance(qaid_list[0], tuple): qaid_list = list(qaid_list[0]) daids_mode = ut.get_argval('--daids-mode', type_=str, default=const.VS_EXEMPLARS_KEY) back.compute_queries(qaid_list=qaid_list, daids_mode=daids_mode, ranks_top=10) if ut.get_argflag('--inc-query'): back.incremental_query() if ut.get_argflag(('--dbinfo', '--display_dbinfo')): back.display_dbinfo() pass aidcmd = ut.get_argval('--aidcmd', default=None) aid = ut.get_argval('--aid', type_=int, default=1) if aidcmd: # aidcmd = 'Interact image' metadata = ibs.get_annot_lazy_dict(aid) annot_context_options = metadata['annot_context_options'] aidcmd_dict = dict(annot_context_options) logger.info('aidcmd_dict = %s' % (ut.repr3(aidcmd_dict), )) command = aidcmd_dict[aidcmd] command() # import utool # utool.embed() # back.start_web_server_parallel() if ut.get_argflag('--start-web'): back.start_web_server_parallel() if ut.get_argflag('--name-tab'): from wbia.gui.guiheaders import NAMES_TREE back.front.set_table_tab(NAMES_TREE) view = back.front.views[NAMES_TREE] model = view.model() view._set_sort(model.col_name_list.index('nAids'), col_sort_reverse=True) if ut.get_argflag('--graph'): back.make_qt_graph_interface() if params.args.postload_exit: logger.info('[main_cmd] postload exit') sys.exit(0)
def get_pipecfg_list(test_cfg_name_list, ibs=None): r""" Builds a list of varied query configurations. Only custom configs depend on an ibs object. The order of the output is not gaurenteed to aggree with input order. Args: test_cfg_name_list (list): list of strs ibs (IBEISController): ibeis controller object (optional) Returns: tuple: (cfg_list, cfgx2_lbl) - cfg_list (list): list of config objects cfgx2_lbl (list): denotes which parameters are being varied. If there is just one config then nothing is varied CommandLine: python -m ibeis.expt.experiment_helpers --exec-get_pipecfg_list:0 python -m ibeis.expt.experiment_helpers --exec-get_pipecfg_list:1 --db humpbacks Example: >>> # ENABLE_DOCTEST >>> from ibeis.expt.experiment_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='testdb1') >>> #test_cfg_name_list = ['best', 'custom', 'custom:sv_on=False'] >>> #test_cfg_name_list = ['default', 'default:sv_on=False', 'best'] >>> test_cfg_name_list = ['default', 'default:sv_on=False', 'best'] >>> # execute function >>> (pcfgdict_list, pipecfg_list) = get_pipecfg_list(test_cfg_name_list, ibs) >>> # verify results >>> assert pipecfg_list[0].sv_cfg.sv_on is True >>> assert pipecfg_list[1].sv_cfg.sv_on is False >>> pipecfg_lbls = get_varied_pipecfg_lbls(pcfgdict_list) >>> result = ('pipecfg_lbls = '+ ut.list_str(pipecfg_lbls)) >>> print(result) pipecfg_lbls = [ 'default:', 'default:sv_on=False', ] Example1: >>> # DISABLE_DOCTEST >>> import ibeis_flukematch.plugin >>> from ibeis.expt.experiment_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='humpbacks') >>> test_cfg_name_list = ['default:pipeline_root=BC_DTW,decision=average,crop_dim_size=[960,500]', 'default:K=[1,4]'] >>> (pcfgdict_list, pipecfg_list) = get_pipecfg_list(test_cfg_name_list, ibs) >>> pipecfg_lbls = get_varied_pipecfg_lbls(pcfgdict_list) >>> result = ('pipecfg_lbls = '+ ut.list_str(pipecfg_lbls)) >>> print(result) >>> print_pipe_configs(pcfgdict_list, pipecfg_list) """ if ut.VERBOSE: print('[expt_help.get_pipecfg_list] building pipecfg_list using: %s' % test_cfg_name_list) if isinstance(test_cfg_name_list, six.string_types): test_cfg_name_list = [test_cfg_name_list] _standard_cfg_names = [] _pcfgdict_list = [] # HACK: Parse out custom configs first for test_cfg_name in test_cfg_name_list: if test_cfg_name.startswith('custom:') or test_cfg_name == 'custom': print('[expthelpers] Parsing nonstandard custom config') if test_cfg_name.startswith('custom:'): # parse out modifications to custom cfgstr_list = ':'.join(test_cfg_name.split(':')[1:]).split(',') augcfgdict = ut.parse_cfgstr_list(cfgstr_list, smartcast=True) else: augcfgdict = {} # Take the configuration from the ibeis object pipe_cfg = ibs.cfg.query_cfg.deepcopy() # Update with augmented params pipe_cfg.update_query_cfg(**augcfgdict) # Parse out a standard cfgdict cfgdict = dict(pipe_cfg.parse_items()) cfgdict['_cfgname'] = 'custom' cfgdict['_cfgstr'] = test_cfg_name _pcfgdict_list.append(cfgdict) else: _standard_cfg_names.append(test_cfg_name) # Handle stanndard configs next if len(_standard_cfg_names) > 0: # Get parsing information #cfg_default_dict = dict(Config.QueryConfig().parse_items()) #valid_keys = list(cfg_default_dict.keys()) cfgstr_list = _standard_cfg_names named_defaults_dict = ut.dict_subset(experiment_configs.__dict__, experiment_configs.TEST_NAMES) alias_keys = experiment_configs.ALIAS_KEYS # Parse standard pipeline cfgstrings metadata = {'ibs': ibs} dict_comb_list = cfghelpers.parse_cfgstr_list2( cfgstr_list, named_defaults_dict, cfgtype=None, alias_keys=alias_keys, # Hack out valid keys for humpbacks #valid_keys=valid_keys, strict=False, metadata=metadata) # Get varied params (there may be duplicates) _pcfgdict_list.extend(ut.flatten(dict_comb_list)) # Expand cfgdicts into PipelineConfig config objects # TODO: respsect different algorithm parameters like flukes if ibs is None: configclass_list = [Config.QueryConfig] * len(_pcfgdict_list) else: root_to_config = ibs.depc_annot.configclass_dict configclass_list = [ root_to_config.get(_cfgdict.get('pipeline_root', 'vsmany'), Config.QueryConfig) for _cfgdict in _pcfgdict_list ] _pipecfg_list = [ cls(**_cfgdict) for cls, _cfgdict in zip(configclass_list, _pcfgdict_list) ] # Enforce rule that removes duplicate configs # by using feasiblity from ibeis.algo.Config # TODO: Move this unique finding code to its own function # and then move it up one function level so even the custom # configs can be uniquified _flag_list = ut.flag_unique_items(_pipecfg_list) cfgdict_list = ut.compress(_pcfgdict_list, _flag_list) pipecfg_list = ut.compress(_pipecfg_list, _flag_list) if ut.NOT_QUIET: #for cfg in _pipecfg_list: # print(cfg.get_cfgstr()) # print(cfg) print('[harn.help] return %d / %d unique pipeline configs from: %r' % (len(cfgdict_list), len(_pcfgdict_list), test_cfg_name_list)) if ut.get_argflag(('--pcfginfo', '--pinfo', '--pipecfginfo')): import sys ut.colorprint('Requested PcfgInfo for tests... ', 'red') print_pipe_configs(cfgdict_list, pipecfg_list) ut.colorprint('Finished Reporting PcfgInfo. Exiting', 'red') sys.exit(0) return (cfgdict_list, pipecfg_list)
def postload_commands(ibs, back): """ Postload commands deal with a specific ibeis database """ if ut.NOT_QUIET: print('\n[main_cmd] postload_commands') if params.args.view_database_directory: print('got arg --vdd') vdd(ibs) if params.args.set_default_dbdir: sysres.set_default_dbdir(ibs.get_dbdir()) if params.args.update_query_cfg is not None: # Set query parameters from command line using the --cfg flag cfgdict = ut.parse_cfgstr_list(params.args.update_query_cfg) print('Custom cfgdict specified') print(ut.dict_str(cfgdict)) ibs.update_query_cfg(**cfgdict) #print(ibs.cfg.query_cfg.get_cfgstr()) if params.args.edit_notes: ut.editfile(ibs.get_dbnotes_fpath(ensure=True)) if params.args.delete_cache: ibs.delete_cache() if params.args.delete_cache_complete: ibs.delete_cache(delete_chips=True, delete_encounters=True) if params.args.delete_query_cache: ibs.delete_qres_cache() if params.args.set_notes is not None: ibs.set_dbnotes(params.args.set_notes) if params.args.set_aids_as_hard is not None: aid_list = params.args.set_aids_as_hard ibs.set_annot_is_hard(aid_list, [True] * len(aid_list)) if params.args.set_all_species is not None: ibs._overwrite_all_annot_species_to(params.args.set_all_species) if params.args.dump_schema: ibs.db.print_schema() if ut.get_argflag('--ipynb'): back.launch_ipy_notebook() select_eid = ut.get_argval(('--select-eid', '--eid',), None) if select_eid is not None: print('\n+ --- CMD SELECT EID=%r ---' % (select_eid,)) # Whoa: this doesnt work. weird. #back.select_eid(select_eid) # This might be the root of gui problems #back.front._change_enc(select_eid) back.front.select_encounter_tab(select_eid) print('L ___ CMD SELECT EID=%r ___\n' % (select_eid,)) # Send commands to GUIBack if params.args.select_aid is not None: if back is not None: try: ibsfuncs.assert_valid_aids(ibs, (params.args.select_aid,)) except AssertionError: print('Valid RIDs are: %r' % (ibs.get_valid_aids(),)) raise back.select_aid(params.args.select_aid) if params.args.select_gid is not None: back.select_gid(params.args.select_gid) if params.args.select_nid is not None: back.select_nid(params.args.select_nid) select_name = ut.get_argval('--select-name') if select_name is not None: import ibeis.gui.guiheaders as gh back.ibswgt.select_table_indicies_from_text(gh.NAMES_TREE, select_name, allow_table_change=True) qaid_list = ut.get_argval(('--query-aid', '--query'), type_=list, default=None) if qaid_list is not None: #qaid_list = params.args.query_aid # fix stride case if len(qaid_list) == 1 and isinstance(qaid_list[0], tuple): qaid_list = list(qaid_list[0]) daids_mode = ut.get_argval('--daids-mode', type_=str, default=const.VS_EXEMPLARS_KEY) back.compute_queries(qaid_list=qaid_list, daids_mode=daids_mode, ranks_lt=10) if ut.get_argflag('--inc-query'): back.incremental_query() if ut.get_argflag(('--dbinfo', '--display_dbinfo')): back.display_dbinfo() pass if ut.get_argflag('--start-web'): back.start_web_server_parallel() #screengrab_fpath = ut.get_argval('--screengrab') #if screengrab_fpath: # from guitool.__PYQT__.QtGui import QPixmap # from PyQt4.QtTest import QTest # from PyQt4.QtCore import Qt # fpath = ut.truepath(screengrab_fpath) # import guitool # #ut.embed() # timer2 = guitool.__PYQT__.QtCore.QTimer() # done = [1000] # def delayed_screenshot_func(): # if done[0] == 500: # #back.mainwin.menubar.triggered.emit(back.mainwin.menuFile) # print('Mouseclick') # QTest.mouseClick(back.mainwin.menuFile, Qt.LeftButton) # # This works # #QTest.mouseClick(back.front.import_button, Qt.LeftButton) # if done[0] == 1: # timer2.stop() # print('screengrab to %r' % (fpath,)) # screenimg = QPixmap.grabWindow(back.mainwin.winId()) # screenimg.save(fpath, 'jpg') # ut.startfile(fpath) # print('lub dub2') # done[0] -= 1 # return None # CLICK_FILE_MENU = True # if CLICK_FILE_MENU: # #ut.embed() # #QTest::keyClick(menu, Qt::Key_Down) # pass # timer2.delayed_screenshot_func = delayed_screenshot_func # timer2.timeout.connect(timer2.delayed_screenshot_func) # timer2.start(1) # back.mainwin.timer2 = timer2 # guitool.activate_qwindow(back.mainwin) # #QPixmap.grabWindow(back.mainwin.winId()).save(fpath, 'jpg') # #ut.startfile(fpath) # #ut.embed() # pass if params.args.postload_exit: print('[main_cmd] postload exit') sys.exit(1)
def customize_base_cfg(cfgname, cfgopt_strs, base_cfg, cfgtype, alias_keys=None, valid_keys=None, offset=0, strict=True): """ Args: cfgname (str): config name cfgopt_strs (str): mini-language defining key variations base_cfg (dict): specifies the default cfg to customize cfgtype (?): alias_keys (None): (default = None) valid_keys (None): if base_cfg is not specied, this defines the valid keys (default = None) offset (int): (default = 0) strict (bool): (default = True) Returns: list: cfg_combo - list of config dicts defining customized configs based on cfgopt_strs. customized configs always are given an _cfgindex, _cfgstr, and _cfgname key. CommandLine: python -m ibeis.expt.cfghelpers --exec-_customize_base_cfg Example: >>> # DISABLE_DOCTEST >>> from ibeis.expt.cfghelpers import * # NOQA >>> cfgname = 'default' >>> cfgopt_strs = 'dsize=1000,per_name=[1,2]' >>> base_cfg = '?' >>> cfgtype = '?' >>> alias_keys = None >>> valid_keys = None >>> offset = 0 >>> strict = True >>> cfg_combo = customize_base_cfg(cfgname, cfgopt_strs, base_cfg, cfgtype, alias_keys, valid_keys, offset, strict) >>> result = ('cfg_combo = %s' % (str(cfg_combo),)) >>> print(result) """ cfg = base_cfg.copy() # Parse dict out of a string #ANYTHING_NOT_BRACE = r'[^\[\]]*\]' ANYTHING_NOT_PAREN_OR_BRACE = r'[^()\[\]]*[\]\)]' cfgstr_options_list = re.split( r',\s*' + ut.negative_lookahead(ANYTHING_NOT_PAREN_OR_BRACE), cfgopt_strs) #cfgstr_options_list = cfgopt_strs.split(',') cfg_options = ut.parse_cfgstr_list( cfgstr_list=cfgstr_options_list, smartcast=True, oldmode=False) # Hack for q/d-prefix specific configs remove_prefix_hack(cfg, cfgtype, cfg_options, alias_keys) # Remap keynames based on aliases if alias_keys is not None: # Use new standard keys and remove old aliased keys for key in set(alias_keys.keys()): if key in cfg_options: cfg_options[alias_keys[key]] = cfg_options[key] del cfg_options[key] # Ensure that nothing bad is being updated if strict: parsed_keys = cfg_options.keys() if valid_keys is not None: ut.assert_all_in(parsed_keys, valid_keys, 'keys specified not in valid set') else: ut.assert_all_in(parsed_keys, cfg.keys(), 'keys specified not in default options') # Finalize configuration dict cfg.update(cfg_options) cfg['_cfgtype'] = cfgtype cfg['_cfgname'] = cfgname cfg_combo = ut.all_dict_combinations(cfg) #if len(cfg_combo) > 1: for combox, cfg_ in enumerate(cfg_combo, start=offset): #cfg_['_cfgname'] += ';' + str(combox) cfg_['_cfgindex'] = combox for cfg_ in cfg_combo: if len(cfgopt_strs) > 0: cfg_['_cfgstr'] = cfg_['_cfgname'] + NAMEVARSEP + cfgopt_strs else: cfg_['_cfgstr'] = cfg_['_cfgname'] return cfg_combo