def on_click_inside(self, event, ax): self.ax = ax self.event = event event = self.event #print(ax) #print(event.x) #print(event.y) aids = list(self.pos.keys()) pos_list = ut.dict_take(self.pos, aids) #x = 10 #y = 10 import numpy as np # NOQA x, y = event.xdata, event.ydata point = np.array([x, y]) pos_list = np.array(pos_list) index, dist = vt.closest_point(point, pos_list, distfunc=vt.L2) print('dist = %r' % (dist,)) aid = aids[index] context_shown = False CHECK_PAIR = True if CHECK_PAIR: if self.event.button == 3 and not context_shown: if len(self.selected_aids) != 2: print('This funciton only work if exactly 2 are selected') else: from ibeis.gui import inspect_gui context_shown = True aid1, aid2 = (self.selected_aids) qres = None qreq_ = None options = inspect_gui.get_aidpair_context_menu_options(ibs, aid1, aid2, qres, qreq_=qreq_) self.show_popup_menu(options, event) SELECT_ANNOT = dist < 35 if SELECT_ANNOT: print(ut.obj_str(ibs.get_annot_info(aid, default=True, name=False, gname=False))) if self.event.button == 1: self.toggle_selected_aid(aid) if self.event.button == 3 and not context_shown: # right click from ibeis.viz.interact import interact_chip context_shown = True #refresh_func = functools.partial(viz.show_name, ibs, nid, fnum=fnum, sel_aids=sel_aids) refresh_func = None config2_ = None options = interact_chip.build_annot_context_options( ibs, aid, refresh_func=refresh_func, with_interact_name=False, config2_=config2_) self.show_popup_menu(options, event) else: if self.event.button == 3: options = [ ('Toggle images', self.toggle_images), ] self.show_popup_menu(options, event)
def get_turk_annot_args(is_reviewed_func): """ Helper to return aids in an imageset or a group review """ ibs = current_app.ibs def _ensureid(_id): return None if _id == 'None' or _id == '' else int(_id) imgsetid = request.args.get('imgsetid', '') src_ag = request.args.get('src_ag', '') dst_ag = request.args.get('dst_ag', '') imgsetid = _ensureid(imgsetid) src_ag = _ensureid(src_ag) dst_ag = _ensureid(dst_ag) group_review_flag = src_ag is not None and dst_ag is not None if not group_review_flag: gid_list = ibs.get_valid_gids(imgsetid=imgsetid) aid_list = ut.flatten(ibs.get_image_aids(gid_list)) reviewed_list = is_reviewed_func(ibs, aid_list) else: src_gar_rowid_list = ibs.get_annotgroup_gar_rowids(src_ag) dst_gar_rowid_list = ibs.get_annotgroup_gar_rowids(dst_ag) src_aid_list = ibs.get_gar_aid(src_gar_rowid_list) dst_aid_list = ibs.get_gar_aid(dst_gar_rowid_list) aid_list = src_aid_list reviewed_list = [ src_aid in dst_aid_list for src_aid in src_aid_list ] try: progress = '%0.2f' % (100.0 * reviewed_list.count(True) / len(aid_list), ) except ZeroDivisionError: progress = '0.00' aid = request.args.get('aid', '') if len(aid) > 0: aid = int(aid) else: aid_list_ = ut.filterfalse_items(aid_list, reviewed_list) if len(aid_list_) == 0: aid = None else: if group_review_flag: aid = aid_list_[0] else: aid = random.choice(aid_list_) previous = request.args.get('previous', None) print('aid = %r' % (aid,)) #print(ut.dict_str(ibs.get_annot_info(aid))) print(ut.obj_str(ibs.get_annot_info(aid, default=True, nl=True))) return aid_list, reviewed_list, imgsetid, src_ag, dst_ag, progress, aid, previous
def get_test_daids(ibs, default_daids='all', qaid_list=None, return_annot_info=False, aidcfg=None): """ Gets database annot_rowids based on command line arguments DEPRICATE CommandLine: python dev.py --db PZ_MTEST -t best --exclude-query --qaid 72 -r 0 -c 0 --show --va --vf --dump-extra Args: ibs (IBEISController): ibeis controller object default_daids (str): (default = 'all') qaid_list (list): list of chosen qaids that may affect daids (default = None) Returns: list: available_daids CommandLine: python -m ibeis.init.main_helpers --test-get_test_daids python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --verbmhelp python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --exclude-query python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --daid-exclude 2 3 4 python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --species=zebra_grevys python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_Master0 --species=zebra_grevys python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_Master0 --controlled --verbmhelp python -m ibeis.init.main_helpers --exec-get_test_daids --controlled --db PZ_Master0 --exec-mode Example: >>> # ENABLE_DOCTEST >>> from ibeis.init.main_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='testdb1') >>> default_daids = 'all' >>> qaid_list = [1] >>> available_daids = get_test_daids(ibs, default_daids, qaid_list) >>> ibeis.other.dbinfo.get_dbinfo(ibs, aid_list=available_daids, with_contrib=False, short=True) >>> result = 'available_daids = ' + ut.obj_str(available_daids, truncate=True, nl=False) >>> print('len(available_daids) %d' % len(available_daids)) >>> print(result) available_daids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] """ daid_request_info = {} if VERB_MAIN_HELPERS: print('[get_test_daids] + --- GET_TEST_DAIDS ---') print('[get_test_daids] * default_daids = %s' % (ut.obj_str(default_daids, truncate=True, nl=False))) print('[get_test_daids] * qaid_list = %s' % (ut.obj_str(qaid_list, truncate=True, nl=False))) # ---- INCLUDING STEP if VERB_MAIN_HELPERS: print('[get_test_daids] * include step') available_daids = [] CONTROLLED_CASES = ut.get_argflag('--controlled') or ut.get_argflag('--controlled_daids') DSHUFFLE = ut.get_argval('--dshuffle') DINDEX = params.args.dindex NO_JUNK = not ut.get_argflag('--junk') EXCLUDE_QUERY = ut.get_argflag('--exclude-query') #daids_exclude = params.args.daid_exclude daids_exclude = None if CONTROLLED_CASES: print('[get_test_daids] * Including controlled daids') from ibeis.other import ibsfuncs controlled_daids = ibsfuncs.get_two_annots_per_name_and_singletons(ibs, onlygt=False) available_daids.extend(controlled_daids) daid_request_info['controlled'] = True else: daid_request_info['controlled'] = False # ---- CHECK_DEFAULTS DATA if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) if len(available_daids) == 0: print('[get_test_daids] * ... defaulting, no available daids on command line.') if isinstance(default_daids, six.string_types): if default_daids == 'all': default_daids = ibs.get_valid_aids() daid_request_info['default_daids'] = 'all' elif default_daids == 'gt': default_daids = ut.flatten(ibs.get_annot_groundtruth(qaid_list)) daid_request_info['default_daids'] = 'gt' #available_qaids = valid_aids[0:1] assert not isinstance(available_daids, six.string_types) available_daids = default_daids else: if VERB_MAIN_HELPERS: print('[get_test_daids] * ... not defaulting') available_daids = ut.unique_ordered(available_daids) # ---- EXCLUSION STEP if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) print('[get_test_daids] * exclude step') species = ut.get_argval('--species', type_=str, default=None) if NO_JUNK: if VERB_MAIN_HELPERS: print('[get_test_daids] * Filtering junk') available_daids = ibs.filter_junk_annotations(available_daids) if EXCLUDE_QUERY: if VERB_MAIN_HELPERS: print('[get_test_daids] * Excluding query qaids') assert qaid_list is not None, 'must specify qaids to exclude' available_daids = ut.setdiff_ordered(available_daids, qaid_list) if daids_exclude is not None: if VERB_MAIN_HELPERS: print('[get_test_daids] * Excluding specified daids') available_daids = ut.setdiff_ordered(available_daids, daids_exclude) if species is not None: if species == 'primary': if VERB_MAIN_HELPERS: print('[get_test_qaids] * Finiding primary species') #species = ibs.get_primary_database_species(available_daids) species = ibs.get_primary_database_species() if VERB_MAIN_HELPERS: print('[get_test_daids] * Filtering to species=%r' % (species,)) import numpy as np isvalid_list = np.array(ibs.get_annot_species(available_daids)) == species available_daids = ut.compress(available_daids, isvalid_list) # ---- SUBINDEXING STEP if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) print('[get_test_daids] * subindex step') #ut.get_argval('--qshuffle') if DSHUFFLE: # Determenistic shuffling available_daids = ut.take(available_daids, ut.random_indexes(len(available_daids), seed=43)) daid_request_info['shuffled'] = True if DINDEX is not None: dindexes = ensure_flatlistlike(DINDEX) _test_daids = [available_daids[dx] for dx in dindexes if dx < len(available_daids)] print('[get_test_daids] Chose subset of size %d/%d' % (len(_test_daids), len(available_daids))) available_daids = _test_daids if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) print('[get_test_daids] L ___ GET_TEST_DAIDS ___') if return_annot_info: return available_daids, daid_request_info else: return available_daids
def get_test_qaids(ibs, default_qaids=None, return_annot_info=False, aidcfg=None): """ Gets test annot_rowids based on command line arguments DEPRICATE Args: ibs (IBEISController): ibeis controller object default_qaids (None): if list then used only if no other aids are available (default = [1]) as a string it mimics the command line Returns: list: available_qaids CommandLine: python -m ibeis.init.main_helpers --test-get_test_qaids python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_Master0 python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_Master0 --qaid 1 python -m ibeis.init.main_helpers --test-get_test_qaids --allgt --db PZ_MTEST python -m ibeis.init.main_helpers --test-get_test_qaids --qaid 4 5 8 --verbmhelp python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_MTEST python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_MTEST --qaid 2 --verbmhelp python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_MTEST --qaid 2 python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_Master0 --qindex 0:10 --verbmhelp python -m ibeis.init.main_helpers --exec-get_test_qaids --controlled --db PZ_Master0 --exec-mode python -m ibeis.init.main_helpers --exec-get_test_qaids --db testdb1 --allgt --qindex 0:256 Example: >>> # ENABLE_DOCTEST >>> from ibeis.init.main_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='testdb1') >>> default_qaids = None >>> available_qaids = get_test_qaids(ibs, default_qaids) >>> ibeis.other.dbinfo.get_dbinfo(ibs, aid_list=available_qaids, with_contrib=False, short=True) >>> result = 'available_qaids = ' + ut.obj_str(available_qaids, truncate=True, nl=False) >>> print('len(available_qaids) = %d' % len(available_qaids)) >>> print(result) available_qaids = [1] """ qaid_request_info = {} if VERB_MAIN_HELPERS: print('[get_test_qaids] + --- GET_TEST_QAIDS ---') # Old version of this function if VERB_MAIN_HELPERS: print('[get_test_qaids] + --- GET_TEST_QAIDS ---') print('[get_test_qaids] * default_qaids = %s' % (ut.obj_str(default_qaids, truncate=True, nl=False))) valid_aids = ibs.get_valid_aids() if len(valid_aids) == 0: print('[get_test_qaids] WARNING no annotations available') # ---- INCLUDING STEP if VERB_MAIN_HELPERS: print('[get_test_qaids] * include step') available_qaids = [] #ut.get_argflag(('--all-cases', '--all')) #ut.get_argflag(('--all-gt-cases', '--allgt')) #ut.get_argflag(('--all-hard-cases', '--allhard')) #ut.get_argflag(('--qaid', '--qaids')) #ut.get_argflag('--controlled') or ut.get_argflag('--controlled_qaids') #not ut.get_argflag('--junk') ALL_CASES = params.args.all_cases or default_qaids == 'all' GT_CASES = params.args.all_gt_cases or default_qaids == 'gt' HARD_CASES = params.args.all_hard_cases or ut.get_argflag(('--all-hard-cases', '--allhard', '--hard')) NO_JUNK = not ut.get_argflag('--junk') CONTROLLED_CASES = ut.get_argflag('--controlled') or ut.get_argflag('--controlled_qaids') NO_REVIEWED = ut.get_argflag('--unreviewed') species = ut.get_argval('--species') #QAID = params.args.qaid QAID = ut.get_argval('--qaid', type_='fuzzy_subset', default=None) QINDEX = params.args.qindex QSHUFFLE = ut.get_argval('--qshuffle') if QAID is not None: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including cmdline specified qaids') try: args_qaid = ensure_flatlistlike(QAID) except Exception: args_qaid = QAID available_qaids.extend(args_qaid) qaid_request_info['custom_commandline'] = args_qaid if ALL_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including all qaids') available_qaids.extend(valid_aids) qaid_request_info['all_cases'] = True if HARD_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including hard qaids') is_hard_list = ibs.get_annot_is_hard(valid_aids) hard_aids = ut.compress(valid_aids, is_hard_list) available_qaids.extend(hard_aids) qaid_request_info['hard_cases'] = True if GT_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including groundtruth qaids') has_gt_list = ibs.get_annot_has_groundtruth(valid_aids) hasgt_aids = ut.compress(valid_aids, has_gt_list) print('[get_test_qaids] Adding all %d/%d ground-truthed test cases' % (len(hasgt_aids), len(valid_aids))) available_qaids.extend(hasgt_aids) qaid_request_info['gt_cases'] = True if CONTROLLED_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including controlled qaids') from ibeis.other import ibsfuncs # Override all other gts with controlled controlled_qaids = ibsfuncs.get_two_annots_per_name_and_singletons(ibs, onlygt=True) available_qaids.extend(controlled_qaids) qaid_request_info['controlled'] = True else: qaid_request_info['controlled'] = False # ---- CHECK_DEFAULTS QUERY if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) if len(available_qaids) == 0: print('[get_test_qaids] * ... defaulting, no available qaids on command line.') if default_qaids is None: default_qaids = valid_aids[0:1] qaid_request_info['default_one'] = True elif isinstance(default_qaids, six.string_types): if default_qaids == 'gt' or default_qaids == 'allgt': default_qaids = ibs.get_valid_aids(hasgt=True) qaid_request_info['default_gt'] = True available_qaids = default_qaids else: if VERB_MAIN_HELPERS: print('[get_test_qaids] * ... not defaulting') available_qaids = ut.unique_ordered(available_qaids) # ---- EXCLUSION STEP if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) print('[get_test_qaids] * exclude step') if NO_JUNK: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Filtering junk') available_qaids = ibs.filter_junk_annotations(available_qaids) qaid_request_info['has_junk'] = False if NO_REVIEWED: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Filtering unreviewed') isreviewed_list = ibs.get_annot_has_reviewed_matching_aids(available_qaids) available_qaids = ut.filterfalse_items(available_qaids, isreviewed_list) qaid_request_info['has_unreviewed'] = False if species is not None: if species == 'primary': if VERB_MAIN_HELPERS: print('[get_test_qaids] * Finiding primary species') #species = ibs.get_primary_database_species(available_qaids) species = ibs.get_primary_database_species() qaid_request_info['primary_species'] = True if VERB_MAIN_HELPERS: print('[get_test_qaids] * Filtering to species=%r' % (species,)) isvalid_list = np.array(ibs.get_annot_species(available_qaids)) == species available_qaids = ut.compress(available_qaids, isvalid_list) qaid_request_info['species_filter'] = species if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) print('[get_test_qaids] * subindex step') # ---- INDEX SUBSET #ut.get_argval('--qshuffle') if QSHUFFLE: # Determenistic shuffling available_qaids = ut.take(available_qaids, ut.random_indexes(len(available_qaids), seed=42)) qaid_request_info['shuffled'] = True # Sample a large pool of chosen query qindexes if QINDEX is not None: # FIXME: should use a slice of the list or a sublist qindexes = ensure_flatlistlike(QINDEX) _test_qaids = [available_qaids[qx] for qx in qindexes if qx < len(available_qaids)] print('[get_test_qaids] Chose subset of size %d/%d' % (len(_test_qaids), len(available_qaids))) available_qaids = _test_qaids qaid_request_info['subset'] = qindexes if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) print('[get_test_qaids] L ___ GET_TEST_QAIDS ___') if return_annot_info: return available_qaids, qaid_request_info else: return available_qaids
def get_test_daids(ibs, default_daids='all', qaid_list=None, return_annot_info=False, aidcfg=None): """ Gets database annot_rowids based on command line arguments DEPRICATE CommandLine: python dev.py --db PZ_MTEST -t best --exclude-query --qaid 72 -r 0 -c 0 --show --va --vf --dump-extra Args: ibs (IBEISController): ibeis controller object default_daids (str): (default = 'all') qaid_list (list): list of chosen qaids that may affect daids (default = None) Returns: list: available_daids CommandLine: python -m ibeis.init.main_helpers --test-get_test_daids python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --verbmhelp python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --exclude-query python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --daid-exclude 2 3 4 python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_MTEST --species=zebra_grevys python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_Master0 --species=zebra_grevys python -m ibeis.init.main_helpers --test-get_test_daids --db PZ_Master0 --controlled --verbmhelp python -m ibeis.init.main_helpers --exec-get_test_daids --controlled --db PZ_Master0 --exec-mode Example: >>> # ENABLE_DOCTEST >>> from ibeis.init.main_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='testdb1') >>> default_daids = 'all' >>> qaid_list = [1] >>> available_daids = get_test_daids(ibs, default_daids, qaid_list) >>> ibeis.other.dbinfo.get_dbinfo(ibs, aid_list=available_daids, with_contrib=False, short=True) >>> result = 'available_daids = ' + ut.obj_str(available_daids, truncate=True, nl=False) >>> print('len(available_daids) %d' % len(available_daids)) >>> print(result) available_daids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] """ daid_request_info = {} if VERB_MAIN_HELPERS: print('[get_test_daids] + --- GET_TEST_DAIDS ---') print('[get_test_daids] * default_daids = %s' % (ut.obj_str(default_daids, truncate=True, nl=False))) print('[get_test_daids] * qaid_list = %s' % (ut.obj_str(qaid_list, truncate=True, nl=False))) # ---- INCLUDING STEP if VERB_MAIN_HELPERS: print('[get_test_daids] * include step') available_daids = [] CONTROLLED_CASES = ut.get_argflag('--controlled') or ut.get_argflag('--controlled_daids') DSHUFFLE = ut.get_argval('--dshuffle') DINDEX = params.args.dindex NO_JUNK = not ut.get_argflag('--junk') EXCLUDE_QUERY = ut.get_argflag('--exclude-query') #daids_exclude = params.args.daid_exclude daids_exclude = None if CONTROLLED_CASES: print('[get_test_daids] * Including controlled daids') from ibeis import ibsfuncs controlled_daids = ibsfuncs.get_two_annots_per_name_and_singletons(ibs, onlygt=False) available_daids.extend(controlled_daids) daid_request_info['controlled'] = True else: daid_request_info['controlled'] = False # ---- CHECK_DEFAULTS DATA if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) if len(available_daids) == 0: print('[get_test_daids] * ... defaulting, no available daids on command line.') if isinstance(default_daids, six.string_types): if default_daids == 'all': default_daids = ibs.get_valid_aids() daid_request_info['default_daids'] = 'all' elif default_daids == 'gt': default_daids = ut.flatten(ibs.get_annot_groundtruth(qaid_list)) daid_request_info['default_daids'] = 'gt' #available_qaids = valid_aids[0:1] assert not isinstance(available_daids, six.string_types) available_daids = default_daids else: if VERB_MAIN_HELPERS: print('[get_test_daids] * ... not defaulting') available_daids = ut.unique_keep_order(available_daids) # ---- EXCLUSION STEP if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) print('[get_test_daids] * exclude step') species = ut.get_argval('--species', type_=str, default=None) if NO_JUNK: if VERB_MAIN_HELPERS: print('[get_test_daids] * Filtering junk') available_daids = ibs.filter_junk_annotations(available_daids) if EXCLUDE_QUERY: if VERB_MAIN_HELPERS: print('[get_test_daids] * Excluding query qaids') assert qaid_list is not None, 'must specify qaids to exclude' available_daids = ut.setdiff_ordered(available_daids, qaid_list) if daids_exclude is not None: if VERB_MAIN_HELPERS: print('[get_test_daids] * Excluding specified daids') available_daids = ut.setdiff_ordered(available_daids, daids_exclude) if species is not None: if species == 'primary': if VERB_MAIN_HELPERS: print('[get_test_qaids] * Finiding primary species') #species = ibs.get_primary_database_species(available_daids) species = ibs.get_primary_database_species() if VERB_MAIN_HELPERS: print('[get_test_daids] * Filtering to species=%r' % (species,)) import numpy as np isvalid_list = np.array(ibs.get_annot_species(available_daids)) == species available_daids = ut.compress(available_daids, isvalid_list) # ---- SUBINDEXING STEP if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) print('[get_test_daids] * subindex step') #ut.get_argval('--qshuffle') if DSHUFFLE: # Determenistic shuffling available_daids = ut.take(available_daids, ut.random_indexes(len(available_daids), seed=43)) daid_request_info['shuffled'] = True if DINDEX is not None: dindexes = ensure_flatlistlike(DINDEX) _test_daids = [available_daids[dx] for dx in dindexes if dx < len(available_daids)] print('[get_test_daids] Chose subset of size %d/%d' % (len(_test_daids), len(available_daids))) available_daids = _test_daids if VERB_MAIN_HELPERS: print('[get_test_daids] * len(available_daids) = %r' % (len(available_daids))) print('[get_test_daids] L ___ GET_TEST_DAIDS ___') if return_annot_info: return available_daids, daid_request_info else: return available_daids
def get_test_qaids(ibs, default_qaids=None, return_annot_info=False, aidcfg=None): """ Gets test annot_rowids based on command line arguments DEPRICATE Args: ibs (IBEISController): ibeis controller object default_qaids (None): if list then used only if no other aids are available (default = [1]) as a string it mimics the command line Returns: list: available_qaids CommandLine: python -m ibeis.init.main_helpers --test-get_test_qaids python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_Master0 python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_Master0 --qaid 1 python -m ibeis.init.main_helpers --test-get_test_qaids --allgt --db PZ_MTEST python -m ibeis.init.main_helpers --test-get_test_qaids --qaid 4 5 8 --verbmhelp python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_MTEST python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_MTEST --qaid 2 --verbmhelp python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_MTEST --qaid 2 python -m ibeis.init.main_helpers --test-get_test_qaids --controlled --db PZ_Master0 --qindex 0:10 --verbmhelp python -m ibeis.init.main_helpers --exec-get_test_qaids --controlled --db PZ_Master0 --exec-mode python -m ibeis.init.main_helpers --exec-get_test_qaids --db testdb1 --allgt --qindex 0:256 Example: >>> # ENABLE_DOCTEST >>> from ibeis.init.main_helpers import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb(defaultdb='testdb1') >>> default_qaids = None >>> available_qaids = get_test_qaids(ibs, default_qaids) >>> ibeis.other.dbinfo.get_dbinfo(ibs, aid_list=available_qaids, with_contrib=False, short=True) >>> result = 'available_qaids = ' + ut.obj_str(available_qaids, truncate=True, nl=False) >>> print('len(available_qaids) = %d' % len(available_qaids)) >>> print(result) available_qaids = [1] """ qaid_request_info = {} if VERB_MAIN_HELPERS: print('[get_test_qaids] + --- GET_TEST_QAIDS ---') # Old version of this function if VERB_MAIN_HELPERS: print('[get_test_qaids] + --- GET_TEST_QAIDS ---') print('[get_test_qaids] * default_qaids = %s' % (ut.obj_str(default_qaids, truncate=True, nl=False))) valid_aids = ibs.get_valid_aids() if len(valid_aids) == 0: print('[get_test_qaids] WARNING no annotations available') # ---- INCLUDING STEP if VERB_MAIN_HELPERS: print('[get_test_qaids] * include step') available_qaids = [] #ut.get_argflag(('--all-cases', '--all')) #ut.get_argflag(('--all-gt-cases', '--allgt')) #ut.get_argflag(('--all-hard-cases', '--allhard')) #ut.get_argflag(('--qaid', '--qaids')) #ut.get_argflag('--controlled') or ut.get_argflag('--controlled_qaids') #not ut.get_argflag('--junk') ALL_CASES = params.args.all_cases or default_qaids == 'all' GT_CASES = params.args.all_gt_cases or default_qaids == 'gt' HARD_CASES = params.args.all_hard_cases or ut.get_argflag(('--all-hard-cases', '--allhard', '--hard')) NO_JUNK = not ut.get_argflag('--junk') CONTROLLED_CASES = ut.get_argflag('--controlled') or ut.get_argflag('--controlled_qaids') NO_REVIEWED = ut.get_argflag('--unreviewed') species = ut.get_argval('--species') #QAID = params.args.qaid QAID = ut.get_argval('--qaid', type_='fuzzy_subset', default=None) QINDEX = params.args.qindex QSHUFFLE = ut.get_argval('--qshuffle') if QAID is not None: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including cmdline specified qaids') try: args_qaid = ensure_flatlistlike(QAID) except Exception: args_qaid = QAID available_qaids.extend(args_qaid) qaid_request_info['custom_commandline'] = args_qaid if ALL_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including all qaids') available_qaids.extend(valid_aids) qaid_request_info['all_cases'] = True if HARD_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including hard qaids') is_hard_list = ibs.get_annot_is_hard(valid_aids) hard_aids = ut.compress(valid_aids, is_hard_list) available_qaids.extend(hard_aids) qaid_request_info['hard_cases'] = True if GT_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including groundtruth qaids') has_gt_list = ibs.get_annot_has_groundtruth(valid_aids) hasgt_aids = ut.compress(valid_aids, has_gt_list) print('[get_test_qaids] Adding all %d/%d ground-truthed test cases' % (len(hasgt_aids), len(valid_aids))) available_qaids.extend(hasgt_aids) qaid_request_info['gt_cases'] = True if CONTROLLED_CASES: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Including controlled qaids') from ibeis import ibsfuncs # Override all other gts with controlled controlled_qaids = ibsfuncs.get_two_annots_per_name_and_singletons(ibs, onlygt=True) available_qaids.extend(controlled_qaids) qaid_request_info['controlled'] = True else: qaid_request_info['controlled'] = False # ---- CHECK_DEFAULTS QUERY if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) if len(available_qaids) == 0: print('[get_test_qaids] * ... defaulting, no available qaids on command line.') if default_qaids is None: default_qaids = valid_aids[0:1] qaid_request_info['default_one'] = True elif isinstance(default_qaids, six.string_types): if default_qaids == 'gt' or default_qaids == 'allgt': default_qaids = ibs.get_valid_aids(hasgt=True) qaid_request_info['default_gt'] = True available_qaids = default_qaids else: if VERB_MAIN_HELPERS: print('[get_test_qaids] * ... not defaulting') available_qaids = ut.unique_keep_order(available_qaids) # ---- EXCLUSION STEP if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) print('[get_test_qaids] * exclude step') if NO_JUNK: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Filtering junk') available_qaids = ibs.filter_junk_annotations(available_qaids) qaid_request_info['has_junk'] = False if NO_REVIEWED: if VERB_MAIN_HELPERS: print('[get_test_qaids] * Filtering unreviewed') isreviewed_list = ibs.get_annot_has_reviewed_matching_aids(available_qaids) available_qaids = ut.filterfalse_items(available_qaids, isreviewed_list) qaid_request_info['has_unreviewed'] = False if species is not None: if species == 'primary': if VERB_MAIN_HELPERS: print('[get_test_qaids] * Finiding primary species') #species = ibs.get_primary_database_species(available_qaids) species = ibs.get_primary_database_species() qaid_request_info['primary_species'] = True if VERB_MAIN_HELPERS: print('[get_test_qaids] * Filtering to species=%r' % (species,)) isvalid_list = np.array(ibs.get_annot_species(available_qaids)) == species available_qaids = ut.compress(available_qaids, isvalid_list) qaid_request_info['species_filter'] = species if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) print('[get_test_qaids] * subindex step') # ---- INDEX SUBSET #ut.get_argval('--qshuffle') if QSHUFFLE: # Determenistic shuffling available_qaids = ut.take(available_qaids, ut.random_indexes(len(available_qaids), seed=42)) qaid_request_info['shuffled'] = True # Sample a large pool of chosen query qindexes if QINDEX is not None: # FIXME: should use a slice of the list or a sublist qindexes = ensure_flatlistlike(QINDEX) _test_qaids = [available_qaids[qx] for qx in qindexes if qx < len(available_qaids)] print('[get_test_qaids] Chose subset of size %d/%d' % (len(_test_qaids), len(available_qaids))) available_qaids = _test_qaids qaid_request_info['subset'] = qindexes if VERB_MAIN_HELPERS: print('[get_test_qaids] * len(available_qaids) = %r' % (len(available_qaids))) print('[get_test_qaids] L ___ GET_TEST_QAIDS ___') if return_annot_info: return available_qaids, qaid_request_info else: return available_qaids
def show_qres(ibs, cm, qreq_=None, **kwargs): """ Display Query Result Logic Defaults to: query chip, groundtruth matches, and top matches Args: ibs (ibeis.IBEISController): ibeis controller object cm (ibeis.ChipMatch): object of feature correspondences and scores Kwargs: in_image (bool) show result in image view if True else chip view annot_mode (int): if annot_mode == 0, then draw lines and ellipse elif annot_mode == 1, then dont draw lines or ellipse elif annot_mode == 2, then draw only lines See: viz_matches.show_name_matches, viz_helpers.get_query_text Returns: mpl.Figure: fig CommandLine: ./main.py --query 1 -y --db PZ_MTEST --noshow-qtres python -m ibeis.viz.viz_qres --test-show_qres --show python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01 python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01 Example: >>> # DISABLE_DOCTEST >>> from ibeis.viz.viz_qres import * # NOQA >>> import plottool as pt >>> ibs, cm, qreq_, kwargs = testdata_show_qres() >>> # execute function >>> fig = show_qres(ibs, cm, show_query=False, qreq_=qreq_, **kwargs) >>> # verify results >>> #fig.show() >>> pt.show_if_requested() """ #ut.print_dict(kwargs) annot_mode = kwargs.get('annot_mode', 1) % 3 # this is toggled figtitle = kwargs.get('figtitle', '') make_figtitle = kwargs.get('make_figtitle', False) aug = kwargs.get('aug', '') top_aids = kwargs.get('top_aids', DEFAULT_NTOP) gt_aids = kwargs.get('gt_aids', []) all_kpts = kwargs.get('all_kpts', False) show_query = kwargs.get('show_query', False) in_image = kwargs.get('in_image', False) sidebyside = kwargs.get('sidebyside', True) #name_scoring = kwargs.get('name_scoring', False) viz_name_score = kwargs.get('viz_name_score', qreq_ is not None) max_nCols = kwargs.get('max_nCols', None) failed_to_match = kwargs.get('failed_to_match', False) fnum = pt.ensure_fnum(kwargs.get('fnum', None)) if ut.VERBOSE and ut.NOT_QUIET: print('query_info = ' + ut.obj_str(ibs.get_annot_info(cm.qaid, default=True, gname=False, name=False, notes=False, exemplar=False), nl=4)) print('top_aids_info = ' + ut.obj_str(ibs.get_annot_info(top_aids, default=True, gname=False, name=False, notes=False, exemplar=False, reference_aid=cm.qaid), nl=4)) if make_figtitle is True: pass #figtitle = cm.make_title(pack=True) #figtitle fig = pt.figure(fnum=fnum, docla=True, doclf=True) if isinstance(top_aids, int): #if isinstance(cm, chip_match.ChipMatch): top_aids = cm.get_top_aids(top_aids) #else: # top_aids = cm.get_top_aids(num=top_aids, name_scoring=name_scoring, ibs=ibs) if failed_to_match: # HACK to visually indicate failure to match in analysis top_aids = [None] + top_aids nTop = len(top_aids) if max_nCols is None: max_nCols = 5 if nTop in [6, 7]: max_nCols = 3 if nTop in [8]: max_nCols = 4 try: assert len(list(set(top_aids).intersection( set(gt_aids)))) == 0, ('gts should be missed. not in top') except AssertionError as ex: ut.printex(ex, keys=['top_aids', 'gt_aids']) raise if ut.DEBUG2: print(cm.get_inspect_str()) #-------------------------------------------------- # Get grid / cell information to build subplot grid #-------------------------------------------------- # Show query or not nQuerySubplts = 1 if show_query else 0 # The top row is given slots for ground truths and querys # all aids in gt_aids should not be in top aids nGtSubplts = nQuerySubplts + (0 if gt_aids is None else len(gt_aids)) # The bottom rows are for the top results nTopNSubplts = nTop nTopNCols = min(max_nCols, nTopNSubplts) nGTCols = min(max_nCols, nGtSubplts) nGTCols = max(nGTCols, nTopNCols) nTopNCols = nGTCols # Get number of rows to show groundtruth nGtRows = 0 if nGTCols == 0 else int(np.ceil(nGtSubplts / nGTCols)) # Get number of rows to show results nTopNRows = 0 if nTopNCols == 0 else int(np.ceil(nTopNSubplts / nTopNCols)) nGtCells = nGtRows * nGTCols # Total number of rows nRows = nTopNRows + nGtRows DEBUG_SHOW_QRES = 0 if DEBUG_SHOW_QRES: allgt_aids = ibs.get_annot_groundtruth(cm.qaid) nSelGt = len(gt_aids) nAllGt = len(allgt_aids) print('[show_qres]========================') print('[show_qres]----------------') print('[show_qres] * annot_mode=%r' % (annot_mode, )) print('[show_qres] #nTop=%r #missed_gts=%r/%r' % (nTop, nSelGt, nAllGt)) print('[show_qres] * -----') print('[show_qres] * nRows=%r' % (nRows, )) print('[show_qres] * nGtSubplts=%r' % (nGtSubplts, )) print('[show_qres] * nTopNSubplts=%r' % (nTopNSubplts, )) print('[show_qres] * nQuerySubplts=%r' % (nQuerySubplts, )) print('[show_qres] * -----') print('[show_qres] * nGTCols=%r' % (nGTCols, )) print('[show_qres] * -----') print('[show_qres] * fnum=%r' % (fnum, )) print('[show_qres] * figtitle=%r' % (figtitle, )) print('[show_qres] * max_nCols=%r' % (max_nCols, )) print('[show_qres] * show_query=%r' % (show_query, )) print('[show_qres] * kwargs=%s' % (ut.dict_str(kwargs), )) # HACK: _color_list = pt.distinct_colors(nTop) aid2_color = {aid: _color_list[ox] for ox, aid in enumerate(top_aids)} ranked_aids = cm.get_top_aids() # Helpers def _show_query_fn(plotx_shift, rowcols): """ helper for show_qres """ plotx = plotx_shift + 1 pnum = (rowcols[0], rowcols[1], plotx) #print('[viz] Plotting Query: pnum=%r' % (pnum,)) _kwshow = dict(draw_kpts=annot_mode) _kwshow.update(kwargs) _kwshow['prefix'] = 'q' _kwshow['pnum'] = pnum _kwshow['aid2_color'] = aid2_color _kwshow['draw_ell'] = annot_mode >= 1 viz_chip.show_chip(ibs, cm.qaid, annote=False, qreq_=qreq_, **_kwshow) def _plot_matches_aids(aid_list, plotx_shift, rowcols): """ helper for show_qres to draw many aids """ _kwshow = dict(draw_ell=annot_mode, draw_pts=False, draw_lines=annot_mode, ell_alpha=.5, all_kpts=all_kpts) _kwshow.update(kwargs) _kwshow['fnum'] = fnum _kwshow['in_image'] = in_image if sidebyside: # Draw each match side by side the query _kwshow['draw_ell'] = annot_mode == 1 _kwshow['draw_lines'] = annot_mode >= 1 else: #print('annot_mode = %r' % (annot_mode,)) _kwshow['draw_ell'] = annot_mode == 1 #_kwshow['draw_pts'] = annot_mode >= 1 #_kwshow['draw_lines'] = False _kwshow['show_query'] = False def _show_matches_fn(aid, orank, pnum): """ Helper function for drawing matches to one aid """ aug = 'rank=%r\n' % orank _kwshow['pnum'] = pnum _kwshow['title_aug'] = aug #draw_ell = annot_mode == 1 #draw_lines = annot_mode >= 1 # If we already are showing the query dont show it here if sidebyside: # Draw each match side by side the query if viz_name_score: cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid), **_kwshow) else: _kwshow['draw_border'] = False _kwshow['draw_lbl'] = False _kwshow['notitle'] = True _kwshow['vert'] = False cm.show_single_annotmatch(qreq_, aid, **_kwshow) #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow) else: # Draw each match by themselves data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2( ) #_kwshow['draw_border'] = kwargs.get('draw_border', True) #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle')) viz_chip.show_chip(ibs, aid, annote=False, notitle=True, data_config2_=data_config2_, **_kwshow) if DEBUG_SHOW_QRES: print('[show_qres()] Plotting Chips %s:' % vh.get_aidstrs(aid_list)) if aid_list is None: return # Do lazy load before show #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2() tblhack = getattr(qreq_, 'tablename', None) # HACK FOR HUMPBACKS # (Also in viz_matches) if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq): # precompute pass #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True) #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True) for ox, aid in enumerate(aid_list): plotx = ox + plotx_shift + 1 pnum = (rowcols[0], rowcols[1], plotx) oranks = np.where(ranked_aids == aid)[0] # This pair has no matches between them. if len(oranks) == 0: orank = -1 if aid is None: pt.imshow_null('Failed to find matches\nfor qaid=%r' % (cm.qaid), fnum=fnum, pnum=pnum, fontsize=18) else: _show_matches_fn(aid, orank, pnum) #if DEBUG_SHOW_QRES: # print('skipping pnum=%r' % (pnum,)) continue if DEBUG_SHOW_QRES: print('pnum=%r' % (pnum, )) orank = oranks[0] + 1 _show_matches_fn(aid, orank, pnum) shift_topN = nGtCells if nGtSubplts == 1: nGTCols = 1 if nRows == 0: pt.imshow_null('[viz_qres] No matches. nRows=0', fnum=fnum) else: fig = pt.figure(fnum=fnum, pnum=(nRows, nGTCols, 1), docla=True, doclf=True) pt.plt.subplot(nRows, nGTCols, 1) # Plot Query if show_query: _show_query_fn(0, (nRows, nGTCols)) # Plot Ground Truth (if given) _plot_matches_aids(gt_aids, nQuerySubplts, (nRows, nGTCols)) # Plot Results _plot_matches_aids(top_aids, shift_topN, (nRows, nTopNCols)) figtitle += aug if failed_to_match: figtitle += '\n No matches found' incanvas = kwargs.get('with_figtitle', not vh.NO_LBL_OVERRIDE) pt.set_figtitle(figtitle, incanvas=incanvas) # Result Interaction return fig
def show_qres(ibs, cm, qreq_=None, **kwargs): """ Display Query Result Logic Defaults to: query chip, groundtruth matches, and top matches Args: ibs (ibeis.IBEISController): ibeis controller object cm (ibeis.ChipMatch): object of feature correspondences and scores Kwargs: in_image (bool) show result in image view if True else chip view annot_mode (int): if annot_mode == 0, then draw lines and ellipse elif annot_mode == 1, then dont draw lines or ellipse elif annot_mode == 2, then draw only lines See: viz_matches.show_name_matches, viz_helpers.get_query_text Returns: mpl.Figure: fig CommandLine: ./main.py --query 1 -y --db PZ_MTEST --noshow-qtres python -m ibeis.viz.viz_qres --test-show_qres --show python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01 python -m ibeis.viz.viz_qres --test-show_qres --show --top-aids=10 --db=PZ_MTEST --sidebyside --annot_mode=0 --notitle --no-viz_name_score --qaids=5 --max_nCols=2 --adjust=.01,.01,.01 Example: >>> # DISABLE_DOCTEST >>> from ibeis.viz.viz_qres import * # NOQA >>> import plottool as pt >>> ibs, cm, qreq_, kwargs = testdata_show_qres() >>> # execute function >>> fig = show_qres(ibs, cm, show_query=False, qreq_=qreq_, **kwargs) >>> # verify results >>> #fig.show() >>> pt.show_if_requested() """ #ut.print_dict(kwargs) annot_mode = kwargs.get('annot_mode', 1) % 3 # this is toggled figtitle = kwargs.get('figtitle', '') make_figtitle = kwargs.get('make_figtitle', False) aug = kwargs.get('aug', '') top_aids = kwargs.get('top_aids', DEFAULT_NTOP) gt_aids = kwargs.get('gt_aids', []) all_kpts = kwargs.get('all_kpts', False) show_query = kwargs.get('show_query', False) in_image = kwargs.get('in_image', False) sidebyside = kwargs.get('sidebyside', True) #name_scoring = kwargs.get('name_scoring', False) viz_name_score = kwargs.get('viz_name_score', qreq_ is not None) max_nCols = kwargs.get('max_nCols', None) failed_to_match = kwargs.get('failed_to_match', False) fnum = pt.ensure_fnum(kwargs.get('fnum', None)) if ut.VERBOSE and ut.NOT_QUIET: print('query_info = ' + ut.obj_str( ibs.get_annot_info(cm.qaid, default=True, gname=False, name=False, notes=False, exemplar=False), nl=4)) print('top_aids_info = ' + ut.obj_str( ibs.get_annot_info(top_aids, default=True, gname=False, name=False, notes=False, exemplar=False, reference_aid=cm.qaid), nl=4)) if make_figtitle is True: pass #figtitle = cm.make_title(pack=True) #figtitle fig = pt.figure(fnum=fnum, docla=True, doclf=True) if isinstance(top_aids, int): #if isinstance(cm, chip_match.ChipMatch): top_aids = cm.get_top_aids(top_aids) #else: # top_aids = cm.get_top_aids(num=top_aids, name_scoring=name_scoring, ibs=ibs) if failed_to_match: # HACK to visually indicate failure to match in analysis top_aids = [None] + top_aids nTop = len(top_aids) if max_nCols is None: max_nCols = 5 if nTop in [6, 7]: max_nCols = 3 if nTop in [8]: max_nCols = 4 try: assert len(list(set(top_aids).intersection(set(gt_aids)))) == 0, ( 'gts should be missed. not in top') except AssertionError as ex: ut.printex(ex, keys=['top_aids', 'gt_aids']) raise if ut.DEBUG2: print(cm.get_inspect_str()) #-------------------------------------------------- # Get grid / cell information to build subplot grid #-------------------------------------------------- # Show query or not nQuerySubplts = 1 if show_query else 0 # The top row is given slots for ground truths and querys # all aids in gt_aids should not be in top aids nGtSubplts = nQuerySubplts + (0 if gt_aids is None else len(gt_aids)) # The bottom rows are for the top results nTopNSubplts = nTop nTopNCols = min(max_nCols, nTopNSubplts) nGTCols = min(max_nCols, nGtSubplts) nGTCols = max(nGTCols, nTopNCols) nTopNCols = nGTCols # Get number of rows to show groundtruth nGtRows = 0 if nGTCols == 0 else int(np.ceil(nGtSubplts / nGTCols)) # Get number of rows to show results nTopNRows = 0 if nTopNCols == 0 else int(np.ceil(nTopNSubplts / nTopNCols)) nGtCells = nGtRows * nGTCols # Total number of rows nRows = nTopNRows + nGtRows DEBUG_SHOW_QRES = 0 if DEBUG_SHOW_QRES: allgt_aids = ibs.get_annot_groundtruth(cm.qaid) nSelGt = len(gt_aids) nAllGt = len(allgt_aids) print('[show_qres]========================') print('[show_qres]----------------') print('[show_qres] * annot_mode=%r' % (annot_mode,)) print('[show_qres] #nTop=%r #missed_gts=%r/%r' % (nTop, nSelGt, nAllGt)) print('[show_qres] * -----') print('[show_qres] * nRows=%r' % (nRows,)) print('[show_qres] * nGtSubplts=%r' % (nGtSubplts,)) print('[show_qres] * nTopNSubplts=%r' % (nTopNSubplts,)) print('[show_qres] * nQuerySubplts=%r' % (nQuerySubplts,)) print('[show_qres] * -----') print('[show_qres] * nGTCols=%r' % (nGTCols,)) print('[show_qres] * -----') print('[show_qres] * fnum=%r' % (fnum,)) print('[show_qres] * figtitle=%r' % (figtitle,)) print('[show_qres] * max_nCols=%r' % (max_nCols,)) print('[show_qres] * show_query=%r' % (show_query,)) print('[show_qres] * kwargs=%s' % (ut.dict_str(kwargs),)) # HACK: _color_list = pt.distinct_colors(nTop) aid2_color = {aid: _color_list[ox] for ox, aid in enumerate(top_aids)} ranked_aids = cm.get_top_aids() # Helpers def _show_query_fn(plotx_shift, rowcols): """ helper for show_qres """ plotx = plotx_shift + 1 pnum = (rowcols[0], rowcols[1], plotx) #print('[viz] Plotting Query: pnum=%r' % (pnum,)) _kwshow = dict(draw_kpts=annot_mode) _kwshow.update(kwargs) _kwshow['prefix'] = 'q' _kwshow['pnum'] = pnum _kwshow['aid2_color'] = aid2_color _kwshow['draw_ell'] = annot_mode >= 1 viz_chip.show_chip(ibs, cm.qaid, annote=False, qreq_=qreq_, **_kwshow) def _plot_matches_aids(aid_list, plotx_shift, rowcols): """ helper for show_qres to draw many aids """ _kwshow = dict(draw_ell=annot_mode, draw_pts=False, draw_lines=annot_mode, ell_alpha=.5, all_kpts=all_kpts) _kwshow.update(kwargs) _kwshow['fnum'] = fnum _kwshow['in_image'] = in_image if sidebyside: # Draw each match side by side the query _kwshow['draw_ell'] = annot_mode == 1 _kwshow['draw_lines'] = annot_mode >= 1 else: #print('annot_mode = %r' % (annot_mode,)) _kwshow['draw_ell'] = annot_mode == 1 #_kwshow['draw_pts'] = annot_mode >= 1 #_kwshow['draw_lines'] = False _kwshow['show_query'] = False def _show_matches_fn(aid, orank, pnum): """ Helper function for drawing matches to one aid """ aug = 'rank=%r\n' % orank _kwshow['pnum'] = pnum _kwshow['title_aug'] = aug #draw_ell = annot_mode == 1 #draw_lines = annot_mode >= 1 # If we already are showing the query dont show it here if sidebyside: # Draw each match side by side the query if viz_name_score: cm.show_single_namematch(qreq_, ibs.get_annot_nids(aid), **_kwshow) else: _kwshow['draw_border'] = False _kwshow['draw_lbl'] = False _kwshow['notitle'] = True _kwshow['vert'] = False cm.show_single_annotmatch(qreq_, aid, **_kwshow) #viz_matches.show_matches(ibs, cm, aid, qreq_=qreq_, **_kwshow) else: # Draw each match by themselves data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2() #_kwshow['draw_border'] = kwargs.get('draw_border', True) #_kwshow['notitle'] = ut.get_argflag(('--no-title', '--notitle')) viz_chip.show_chip(ibs, aid, annote=False, notitle=True, data_config2_=data_config2_, **_kwshow) if DEBUG_SHOW_QRES: print('[show_qres()] Plotting Chips %s:' % vh.get_aidstrs(aid_list)) if aid_list is None: return # Do lazy load before show #data_config2_ = None if qreq_ is None else qreq_.get_external_data_config2() tblhack = getattr(qreq_, 'tablename', None) # HACK FOR HUMPBACKS # (Also in viz_matches) if tblhack == 'vsone' or (qreq_ is not None and not qreq_._isnewreq): # precompute pass #ibs.get_annot_chips(aid_list, config2_=data_config2_, ensure=True) #ibs.get_annot_kpts(aid_list, config2_=data_config2_, ensure=True) for ox, aid in enumerate(aid_list): plotx = ox + plotx_shift + 1 pnum = (rowcols[0], rowcols[1], plotx) oranks = np.where(ranked_aids == aid)[0] # This pair has no matches between them. if len(oranks) == 0: orank = -1 if aid is None: pt.imshow_null('Failed to find matches\nfor qaid=%r' % (cm.qaid), fnum=fnum, pnum=pnum, fontsize=18) else: _show_matches_fn(aid, orank, pnum) #if DEBUG_SHOW_QRES: # print('skipping pnum=%r' % (pnum,)) continue if DEBUG_SHOW_QRES: print('pnum=%r' % (pnum,)) orank = oranks[0] + 1 _show_matches_fn(aid, orank, pnum) shift_topN = nGtCells if nGtSubplts == 1: nGTCols = 1 if nRows == 0: pt.imshow_null('[viz_qres] No matches. nRows=0', fnum=fnum) else: fig = pt.figure(fnum=fnum, pnum=(nRows, nGTCols, 1), docla=True, doclf=True) pt.plt.subplot(nRows, nGTCols, 1) # Plot Query if show_query: _show_query_fn(0, (nRows, nGTCols)) # Plot Ground Truth (if given) _plot_matches_aids(gt_aids, nQuerySubplts, (nRows, nGTCols)) # Plot Results _plot_matches_aids(top_aids, shift_topN, (nRows, nTopNCols)) figtitle += aug if failed_to_match: figtitle += '\n No matches found' incanvas = kwargs.get('with_figtitle', not vh.NO_LBL_OVERRIDE) pt.set_figtitle(figtitle, incanvas=incanvas) # Result Interaction return fig
def print_annot_info(): print('[interact_chip] Annotation Info = ' + ut.obj_str(annot_info, nl=4)) print('config2_ = %r' % (config2_,)) if config2_ is not None: print('config2_.__dict__ = %s' % (ut.repr3(config2_.__dict__),))
def print_annot_info(): print('[interact_chip] Annotation Info = ' + ut.obj_str(annot_info, nl=4))