Exemplo n.º 1
0
def try_download_baseline_ibeis_normalizer(ibs, qreq_):
    """
    tries to download a baseline normalizer for some species.
    creates an empty normalizer if it cannot
    """
    baseline_url_dict = {
        # TODO: Populate
    }
    species_text = '_'.join(qreq_.get_unique_species())  # HACK
    query_cfgstr = qreq_.qparams.query_cfgstr
    cachedir = qreq_.ibs.get_global_species_scorenorm_cachedir(species_text)
    key = species_text + query_cfgstr
    baseline_url = baseline_url_dict.get(key, None)
    if baseline_url is not None:
        try:
            cachedir = qreq_.ibs.get_global_species_scorenorm_cachedir(species_text)
            baseline_cachedir = join(cachedir, 'baseline')
            ut.ensuredir(baseline_cachedir)
            encoder = vt.ScoreNormalizer(cfgstr=query_cfgstr, prefix=species_text)
            encoder.load(baseline_cachedir)
        except Exception:
            encoder = None
    else:
        encoder = None
    if encoder is None:
        if False and ut.is_developer(['hyrule']):
            # train new encoder. only do this on hyrule
            print('Baseline does not exist and cannot be downlaoded. Training baseline')
            encoder = train_baseline_ibeis_normalizer(qreq_.ibs)
        else:
            # return empty score encoder
            encoder = vt.ScoreNormalizer(cfgstr=query_cfgstr, prefix=species_text)
            print('returning empty encoder')
            #raise NotImplementedError('return the nodata noramlizer with 1/2 default')
    return encoder
Exemplo n.º 2
0
def get_dbalias_dict():
    # HACK: DEPRICATE
    dbalias_dict = {}
    if ut.is_developer():
        # For jon's convinience
        dbalias_dict.update(
            {
                'NAUTS': 'NAUT_Dan',
                'WD': 'WD_Siva',
                'LF': 'LF_all',
                'GZ': 'GZ_ALL',
                'MOTHERS': 'PZ_MOTHERS',
                'FROGS': 'Frogs',
                'TOADS': 'WY_Toads',
                'SEALS_SPOTTED': 'Seals',
                'OXFORD': 'Oxford_Buildings',
                'PARIS': 'Paris_Buildings',
                'JAG_KELLY': 'JAG_Kelly',
                'JAG_KIERYN': 'JAG_Kieryn',
                'WILDEBEAST': 'Wildebeast',
                'WDOGS': 'WD_Siva',
                'PZ': 'PZ_FlankHack',
                'PZ2': 'PZ-Sweatwater',
                'PZ_MARIANNE': 'PZ_Marianne',
                'PZ_DANEXT_TEST': 'PZ_DanExt_Test',
                'PZ_DANEXT_ALL': 'PZ_DanExt_All',
                'LF_ALL': 'LF_all',
                'WS_HARD': 'WS_hard',
                'SONOGRAMS': 'sonograms',
            }
        )
        dbalias_dict['JAG'] = dbalias_dict['JAG_KELLY']
    return dbalias_dict
Exemplo n.º 3
0
def get_dbalias_dict():
    dbalias_dict = {}
    if ut.is_developer():
        # For jon's convinience
        dbalias_dict.update({
            'NAUTS':            'NAUT_Dan',
            'WD':               'WD_Siva',
            'LF':               'LF_all',
            'GZ':               'GZ_ALL',
            'MOTHERS':          'PZ_MOTHERS',
            'FROGS':            'Frogs',
            'TOADS':            'WY_Toads',
            'SEALS_SPOTTED':    'Seals',

            'OXFORD':           'Oxford_Buildings',
            'PARIS':            'Paris_Buildings',

            'JAG_KELLY':        'JAG_Kelly',
            'JAG_KIERYN':       'JAG_Kieryn',
            'WILDEBEAST':       'Wildebeast',
            'WDOGS':            'WD_Siva',

            'PZ':               'PZ_FlankHack',
            'PZ2':              'PZ-Sweatwater',
            'PZ_MARIANNE':      'PZ_Marianne',
            'PZ_DANEXT_TEST':   'PZ_DanExt_Test',
            'PZ_DANEXT_ALL':    'PZ_DanExt_All',

            'LF_ALL':           'LF_all',
            'WS_HARD':          'WS_hard',
            'SONOGRAMS':        'sonograms',

        })
        dbalias_dict['JAG'] = dbalias_dict['JAG_KELLY']
    return dbalias_dict
Exemplo n.º 4
0
 def __init__(self, ibs, aid1, aid2, update_callback=None,
              backend_callback=None, dodraw=True, max_cols=MAX_COLS, **kwargs):
     if ut.VERBOSE:
         print('[matchver] __init__')
     if ut.VERBOSE or ut.is_developer():
         print('[matchver] __init__ aid1=%r, aid2=%r ' % (aid1, aid2))
     super(MatchVerificationInteraction, self).__init__(**kwargs)
     self.ibs = ibs
     self.max_cols = max_cols
     self.aid1 = aid1
     self.aid2 = aid2
     self.col_offset_list = [0, 0]
     #ibsfuncs.assert_valid_aids(ibs, [aid1, aid2])
     def _nonefn():
         return None
     if update_callback is None:
         update_callback = _nonefn
     if backend_callback is None:
         backend_callback = _nonefn
     self.update_callback = update_callback  # if something like qt needs a manual refresh on change
     self.backend_callback = backend_callback
     self.qres_callback = kwargs.get('qres_callback', None)
     self.cm = kwargs.get('cm', None)
     self.qreq_ = kwargs.get('qreq_', None)
     if self.cm is not None:
         from ibeis.algo.hots import chip_match
         assert isinstance(self.cm, chip_match.ChipMatch)
         assert self.qreq_ is not None
     self.infer_data()
     if dodraw:
         self.show_page(bring_to_front=True)
Exemplo n.º 5
0
def ensure_user_profile(user_profile=None):
    r"""
    Args:
        user_profile (UserProfile): (default = None)

    Returns:
        UserProfile: user_profile

    CommandLine:
        python -m utool.util_project --exec-ensure_user_profile --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from utool.util_project import *  # NOQA
        >>> import utool as ut
        >>> user_profile = None
        >>> user_profile = ensure_user_profile(user_profile)
        >>> result = ('user_profile = %s' % (ut.repr2(user_profile),))
        >>> print(ut.repr3(user_profile.project_dpaths))
        >>> print(result)
    """
    global __GLOBAL_PROFILE__
    if __GLOBAL_PROFILE__ is None:
        import utool as ut
        if ut.is_developer():
            __GLOBAL_PROFILE__ = ibeis_user_profile()
    if user_profile is None:
        user_profile = __GLOBAL_PROFILE__
    return user_profile
Exemplo n.º 6
0
    def infer_data(self):
        """ Initialize data related to the input aids
        """
        ibs = self.ibs
        # The two matching aids
        self.aid_pair = (self.aid1, self.aid2)
        (aid1, aid2) = self.aid_pair
        self.match_text = ibs.get_match_text(self.aid1, self.aid2)
        # The names of the matching annotations
        self.nid1, self.nid2 = ibs.get_annot_name_rowids((aid1, aid2))
        self.name1, self.name2 = ibs.get_annot_names((aid1, aid2))
        self.other_valid_nids = []
        # The other annotations that belong to these two names
        self.gts_list = ibs.get_annot_groundtruth((aid1, aid2))
        self.gt1, self.gt2 = self.gts_list
        # A flat list of all the aids we are looking at
        self.is_split_case = self.nid1 == self.nid2
        self.all_aid_list = ut.unique_ordered([aid1, aid2] + self.gt1 +
                                              self.gt2)
        self.all_nid_list_orig = ibs.get_annot_name_rowids(self.all_aid_list)
        self.other_aids = list(
            set(self.all_aid_list) - set([self.aid1, self.aid2]))

        if self.is_split_case:
            # Split case
            self.nCols = max(2, len(self.other_aids))
            self.nRows = 2 if len(self.other_aids) > 0 else 1
        else:
            # Merge/New Match case
            self.nCols = max(len(self.gt1) + 1, len(self.gt2) + 1)
            self.nRows = 2
        self.nCols = min(self.max_cols, self.nCols)

        # Grab not just the exemplars

        if ut.VERBOSE or ut.is_developer():
            logger.info('[matchver] __init__ nid1=%r, nid2=%r ' %
                        (self.nid1, self.nid2))
            logger.info('[matchver] __init__ self.gts_list=%r ' %
                        (self.gts_list))

        if ut.VERBOSE or ut.is_developer():
            logger.info('[matchver] __init__ nid1=%r, nid2=%r ' %
                        (self.nid1, self.nid2))
            logger.info('[matchver] __init__ self.gts_list=%r ' %
                        (self.gts_list))
Exemplo n.º 7
0
def testdata_expts(defaultdb='testdb1',
                   default_acfgstr_name_list=['default:qindex=0:10:4,dindex=0:20'],
                   default_test_cfg_name_list=['default'],
                   a=None,
                   t=None,
                   qaid_override=None,
                   daid_override=None,
                   initial_aids=None,
                   ):
    """
    Use this if you want data from an experiment.
    Command line interface to quickly get testdata for test_results.

    Command line flags can be used to specify db, aidcfg, pipecfg, qaid
    override, daid override (and maybe initial aids).

    """
    print('[main_helpers] testdata_expts')
    import ibeis
    from ibeis.expt import experiment_harness
    from ibeis.expt import test_result
    if a is not None:
        default_acfgstr_name_list = a
    if t is not None:
        default_test_cfg_name_list = t

    if isinstance(default_acfgstr_name_list, six.string_types):
        default_acfgstr_name_list = [default_acfgstr_name_list]
    if isinstance(default_test_cfg_name_list, six.string_types):
        default_test_cfg_name_list = [default_test_cfg_name_list]

    #from ibeis.expt import experiment_helpers
    ibs = ibeis.opendb(defaultdb=defaultdb)
    acfg_name_list = ut.get_argval(('--aidcfg', '--acfg', '-a'), type_=list,
                                   default=default_acfgstr_name_list)
    test_cfg_name_list = ut.get_argval(('-t', '-p'), type_=list, default=default_test_cfg_name_list)
    daid_override = ut.get_argval(('--daid-override', '--daids-override'), type_=list, default=daid_override)
    qaid_override = ut.get_argval(('--qaid', '--qaids-override', '--qaid-override'), type_=list, default=qaid_override)

    # Hack a cache here
    use_bigtest_cache3 = not ut.get_argflag(('--nocache', '--nocache-hs'))
    use_bigtest_cache3 &= ut.is_developer()
    use_bigtest_cache3 &= False
    if use_bigtest_cache3:
        from os.path import dirname, join
        cache_dir = ut.ensuredir(join(dirname(ut.get_module_dir(ibeis)), 'BIG_TESTLIST_CACHE3'))
        load_testres = ut.cached_func('testreslist', cache_dir=cache_dir)(experiment_harness.run_test_configurations2)
    else:
        load_testres = experiment_harness.run_test_configurations2
    testres_list = load_testres(
        ibs, acfg_name_list, test_cfg_name_list, qaid_override=qaid_override,
        daid_override=daid_override, initial_aids=initial_aids)
    testres = test_result.combine_testres_list(ibs, testres_list)

    print(testres)

    return ibs, testres
Exemplo n.º 8
0
    def infer_data(self):
        """ Initialize data related to the input aids
        """
        ibs = self.ibs
        # The two matching aids
        self.aid_pair = (self.aid1, self.aid2)
        (aid1, aid2) = self.aid_pair
        self.match_text = ibs.get_match_text(self.aid1, self.aid2)
        # The names of the matching annotations
        self.nid1, self.nid2 = ibs.get_annot_name_rowids((aid1, aid2))
        self.name1, self.name2 = ibs.get_annot_names((aid1, aid2))
        self.other_valid_nids = []
        # The other annotations that belong to these two names
        self.gts_list  = ibs.get_annot_groundtruth((aid1, aid2))
        self.gt1, self.gt2 = self.gts_list
        # A flat list of all the aids we are looking at
        self.is_split_case = self.nid1 == self.nid2
        self.all_aid_list = ut.unique_ordered([aid1, aid2] + self.gt1 + self.gt2)
        self.all_nid_list_orig = ibs.get_annot_name_rowids(self.all_aid_list)
        self.other_aids = list(set(self.all_aid_list) - set([self.aid1, self.aid2]))

        if self.is_split_case:
            # Split case
            self.nCols = max(2, len(self.other_aids))
            self.nRows = 2 if len(self.other_aids) > 0 else 1
        else:
            # Merge/New Match case
            self.nCols = max(len(self.gt1) + 1, len(self.gt2) + 1)
            self.nRows = 2
        self.nCols = min(self.max_cols, self.nCols)

        # Grab not just the exemplars

        if ut.VERBOSE or ut.is_developer():
            print('[matchver] __init__ nid1=%r, nid2=%r ' % (self.nid1, self.nid2))
            print('[matchver] __init__ self.gts_list=%r ' % (self.gts_list))

        if ut.VERBOSE or ut.is_developer():
            print('[matchver] __init__ nid1=%r, nid2=%r ' % (self.nid1, self.nid2))
            print('[matchver] __init__ self.gts_list=%r ' % (self.gts_list))
Exemplo n.º 9
0
def find_tomcat(verbose=ut.NOT_QUIET):
    r"""
    Searches likely places for tomcat to be installed

    Returns:
        str: tomcat_dpath

    Ignore:
        locate --regex "tomcat/webapps$"

    CommandLine:
        python -m ibeis find_tomcat

    Example:
        >>> # SCRIPT
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> tomcat_dpath = find_tomcat()
        >>> result = ('tomcat_dpath = %s' % (str(tomcat_dpath),))
        >>> print(result)
    """
    # Tomcat folder must be named one of these and contain specific files
    fname_list = ['Tomcat', 'tomcat']
    #required_subpaths = ['webapps', 'bin', 'bin/catalina.sh']
    required_subpaths = ['webapps']

    # Places for local install of tomcat
    priority_paths = [
        # Number one preference is the CATALINA_HOME directory
        os.environ.get('CATALINA_HOME', None),
        # We put tomcat here if we can't find it
        ut.get_app_resource_dir('ibeis', 'tomcat')
    ]
    if ut.is_developer():
        # For my machine to use local catilina
        dpath_list = []
    else:
        # Places for system install of tomcat
        if ut.WIN32:
            dpath_list = ['C:/Program Files (x86)', 'C:/Program Files']
        elif ut.DARWIN:
            dpath_list = ['/Library']  # + dpath_list
        else:
            dpath_list = ['/var/lib', '/usr/share', '/opt', '/lib']
    return_path = ut.search_candidate_paths(dpath_list,
                                            fname_list,
                                            priority_paths,
                                            required_subpaths,
                                            verbose=verbose)
    tomcat_dpath = return_path
    print('tomcat_dpath = %r ' % (tomcat_dpath, ))
    return tomcat_dpath
Exemplo n.º 10
0
def find_tomcat(verbose=ut.NOT_QUIET):
    r"""
    Searches likely places for tomcat to be installed

    Returns:
        str: tomcat_dpath

    Ignore:
        locate --regex "tomcat/webapps$"

    CommandLine:
        python -m ibeis find_tomcat

    Example:
        >>> # SCRIPT
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> tomcat_dpath = find_tomcat()
        >>> result = ('tomcat_dpath = %s' % (str(tomcat_dpath),))
        >>> print(result)
    """
    # Tomcat folder must be named one of these and contain specific files
    fname_list = ['Tomcat', 'tomcat']
    #required_subpaths = ['webapps', 'bin', 'bin/catalina.sh']
    required_subpaths = ['webapps']

    # Places for local install of tomcat
    priority_paths = [
        # Number one preference is the CATALINA_HOME directory
        os.environ.get('CATALINA_HOME', None),
        # We put tomcat here if we can't find it
        ut.get_app_resource_dir('ibeis', 'tomcat')
    ]
    if ut.is_developer():
        # For my machine to use local catilina
        dpath_list = []
    else:
        # Places for system install of tomcat
        if ut.WIN32:
            dpath_list = ['C:/Program Files (x86)', 'C:/Program Files']
        elif ut.DARWIN:
            dpath_list = ['/Library'] + dpath_list
        else:
            dpath_list = ['/var/lib', '/usr/share', '/opt', '/lib']
    return_path = ut.search_candidate_paths(
        dpath_list, fname_list, priority_paths, required_subpaths,
        verbose=verbose)
    tomcat_dpath = return_path
    print('tomcat_dpath = %r ' % (tomcat_dpath,))
    return tomcat_dpath
Exemplo n.º 11
0
        def make_cacher(name, cfgstr=None):
            if cfgstr is None:
                cfgstr = ut.hashstr27(qreq_.get_cfgstr())
            if False and ut.is_developer():
                return ut.Cacher(fname=name + '_' + qreq_.ibs.get_dbname(),
                                 cfgstr=cfgstr,
                                 cache_dir=ut.ensuredir(
                                     ut.truepath('~/Desktop/smkcache')))
            else:
                wrp = ut.DynStruct()

                def ensure(func):
                    return func()

                wrp.ensure = ensure
                return wrp
Exemplo n.º 12
0
    def __init__(
        self,
        ibs,
        aid1,
        aid2,
        update_callback=None,
        backend_callback=None,
        dodraw=True,
        max_cols=MAX_COLS,
        **kwargs,
    ):
        if ut.VERBOSE:
            logger.info('[matchver] __init__')
        if ut.VERBOSE or ut.is_developer():
            logger.info('[matchver] __init__ aid1=%r, aid2=%r ' % (aid1, aid2))
        super(MatchVerificationInteraction, self).__init__(**kwargs)
        self.ibs = ibs
        self.max_cols = max_cols
        self.aid1 = aid1
        self.aid2 = aid2
        self.col_offset_list = [0, 0]

        # ibsfuncs.assert_valid_aids(ibs, [aid1, aid2])

        def _nonefn():
            return None

        if update_callback is None:
            update_callback = _nonefn
        if backend_callback is None:
            backend_callback = _nonefn
        self.update_callback = (
            update_callback  # if something like qt needs a manual refresh on change
        )
        self.backend_callback = backend_callback
        self.qres_callback = kwargs.get('qres_callback', None)
        self.cm = kwargs.get('cm', None)
        self.qreq_ = kwargs.get('qreq_', None)
        if self.cm is not None:
            from wbia.algo.hots import chip_match

            assert isinstance(self.cm, chip_match.ChipMatch)
            assert self.qreq_ is not None
        self.infer_data()
        if dodraw:
            self.show_page(bring_to_front=True)
Exemplo n.º 13
0
    def get_popup_options(self):
        from wbia.gui import inspect_gui

        options = []

        ax = pt.gca()  # HACK

        from wbia.plottool import plot_helpers as ph

        viztype = ph.get_plotdat(ax, 'viztype', '')
        is_match_type = viztype in ['matches', 'multi_match']

        if is_match_type:
            options += inspect_gui.get_aidpair_context_menu_options(
                self.ibs,
                self.qaid,
                self.daid,
                self.cm,
                qreq_=self.qreq_,
                # update_callback=self.show_page,
                # backend_callback=None, aid_list=aid_list)
            )

        options += [
            # ('Toggle same_fig', self.toggle_samefig),
            # ('Toggle vert', self.toggle_vert),
            ('query last feature', self.query_last_feature),
            ('show each chip', self.show_each_chip),
            ('show each distinctiveness chip', self.show_each_dstncvs_chip),
            ('show each foreground weight chip', self.show_each_fgweight_chip),
            ('show each probchip', self.show_each_probchip),
            ('show coverage', self.show_coverage),
            # ('show each probchip', self.query_last_feature),
        ]

        # options.append(('name_interaction', self.name_interaction))
        # if self.H1 is not None:
        #    options.append(('Toggle homog', self.toggle_homog))
        if ut.is_developer():
            options.append(('dev_reload', self.dev_reload))
            options.append(('dev_embed', self.dev_embed))
        # options.append(('cancel', lambda: print('cancel')))
        options += super(MatchInteraction, self).get_popup_options()

        return options
Exemplo n.º 14
0
def get_big_test_cache_info(ibs, cfgx2_qreq_):
    """
    Args:
        ibs (ibeis.IBEISController):
        cfgx2_qreq_ (dict):
    """
    if ut.is_developer():
        import ibeis
        repodir = dirname(ut.get_module_dir(ibeis))
        bt_cachedir = join(repodir, 'BIG_TEST_CACHE2')
    else:
        bt_cachedir = join(ibs.get_cachedir(), 'BIG_TEST_CACHE2')
        #bt_cachedir = './localdata/BIG_TEST_CACHE2'
    ut.ensuredir(bt_cachedir)
    bt_cachestr = ut.hashstr_arr27(
        [qreq_.get_cfgstr(with_input=True) for qreq_ in cfgx2_qreq_],
        ibs.get_dbname() + '_cfgs')
    bt_cachename = 'BIGTESTCACHE2'
    return bt_cachedir, bt_cachename, bt_cachestr
Exemplo n.º 15
0
    def publish(dstcnvs_normer, cachedir=None):
        """
        Sets this as the default normalizer available for download
        ONLY DEVELOPERS CAN PERFORM THIS OPERATION

        Args:
            cachedir (str):

        CommandLine:
            python -m wbia.algo.hots.distinctiveness_normalizer --test-publish

        Example:
            >>> # DISABLE_DOCTEST
            >>> from wbia.algo.hots.distinctiveness_normalizer import *  # NOQA
            >>> dstcnvs_normer = testdata_distinctiveness()[0]
            >>> dstcnvs_normer.rebuild()
            >>> dstcnvs_normer.save()
            >>> result = dstcnvs_normer.publish(cachedir)
            >>> # verify results
            >>> print(result)
        """
        from os.path import basename, join

        assert ut.is_developer(), 'ONLY DEVELOPERS CAN PERFORM THIS OPERATION'
        cachedir = dstcnvs_normer.cachedir if cachedir is None else cachedir
        archive_fpath = dstcnvs_normer.archive(cachedir, overwrite=True)
        archive_fname = basename(archive_fpath)
        publish_dpath = PUBLISH_DIR
        publish_fpath = join(publish_dpath, archive_fname)
        if ut.checkpath(publish_fpath, verbose=True):
            logger.info('Overwriting model')
            logger.info(
                'old nBytes(publish_fpath) = %s'
                % (ut.get_file_nBytes_str(publish_fpath),)
            )
            logger.info(
                'new nBytes(archive_fpath) = %s'
                % (ut.get_file_nBytes_str(archive_fpath),)
            )
        else:
            logger.info('Publishing model')
        logger.info('publish_fpath = %r' % (publish_fpath,))
        ut.copy(archive_fpath, publish_fpath)
Exemplo n.º 16
0
def get_big_test_cache_info(ibs, cfgx2_qreq_):
    """
    Args:
        ibs (ibeis.IBEISController):
        cfgx2_qreq_ (dict):
    """
    if ut.is_developer():
        import ibeis
        repodir = dirname(ut.get_module_dir(ibeis))
        bt_cachedir = join(repodir, 'BIG_TEST_CACHE2')
    else:
        bt_cachedir = join(ibs.get_cachedir(), 'BIG_TEST_CACHE2')
        #bt_cachedir = './localdata/BIG_TEST_CACHE2'
    ut.ensuredir(bt_cachedir)
    bt_cachestr = ut.hashstr_arr27([
        qreq_.get_cfgstr(with_input=True)
        for qreq_ in cfgx2_qreq_],
        ibs.get_dbname() + '_cfgs')
    bt_cachename = 'BIGTESTCACHE2'
    return bt_cachedir, bt_cachename, bt_cachestr
Exemplo n.º 17
0
def testdata_ensure_unconverted_hsdb():
    r"""
    Makes an unconverted test datapath

    CommandLine:
        python -m ibeis.dbio.ingest_hsdb --test-testdata_ensure_unconverted_hsdb

    Example:
        >>> # SCRIPT
        >>> from ibeis.dbio.ingest_hsdb import *  # NOQA
        >>> result = testdata_ensure_unconverted_hsdb()
        >>> print(result)
    """
    import utool as ut
    assert ut.is_developer(), 'dev function only'
    # Make an unconverted test database
    ut.ensurepath('/raid/tests/tmp')
    ut.delete('/raid/tests/tmp/Frogs')
    ut.copy('/raid/tests/Frogs', '/raid/tests/tmp/Frogs')
    hsdb_dir = '/raid/tests/tmp/Frogs'
    return hsdb_dir
Exemplo n.º 18
0
def testdata_ensure_unconverted_hsdb():
    r"""
    Makes an unconverted test datapath

    CommandLine:
        python -m ibeis.dbio.ingest_hsdb --test-testdata_ensure_unconverted_hsdb

    Example:
        >>> # SCRIPT
        >>> from ibeis.dbio.ingest_hsdb import *  # NOQA
        >>> result = testdata_ensure_unconverted_hsdb()
        >>> print(result)
    """
    import utool as ut
    assert ut.is_developer(), 'dev function only'
    # Make an unconverted test database
    ut.ensurepath('/raid/tests/tmp')
    ut.delete('/raid/tests/tmp/Frogs')
    ut.copy('/raid/tests/Frogs', '/raid/tests/tmp/Frogs')
    hsdb_dir = '/raid/tests/tmp/Frogs'
    return hsdb_dir
Exemplo n.º 19
0
    def publish(dstcnvs_normer, cachedir=None):
        """
        Sets this as the default normalizer available for download
        ONLY DEVELOPERS CAN PERFORM THIS OPERATION

        Args:
            cachedir (str):

        CommandLine:
            python -m ibeis.algo.hots.distinctiveness_normalizer --test-publish

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.algo.hots.distinctiveness_normalizer import *  # NOQA
            >>> dstcnvs_normer = testdata_distinctiveness()[0]
            >>> dstcnvs_normer.rebuild()
            >>> dstcnvs_normer.save()
            >>> result = dstcnvs_normer.publish(cachedir)
            >>> # verify results
            >>> print(result)
        """
        from os.path import basename, join
        assert ut.is_developer(), 'ONLY DEVELOPERS CAN PERFORM THIS OPERATION'
        cachedir      = dstcnvs_normer.cachedir if cachedir is None else cachedir
        archive_fpath = dstcnvs_normer.archive(cachedir, overwrite=True)
        archive_fname = basename(archive_fpath)
        publish_dpath = PUBLISH_DIR
        publish_fpath = join(publish_dpath, archive_fname)
        if ut.checkpath(publish_fpath, verbose=True):
            print('Overwriting model')
            print('old nBytes(publish_fpath) = %s' %
                  (ut.get_file_nBytes_str(publish_fpath),))
            print('new nBytes(archive_fpath) = %s' %
                  (ut.get_file_nBytes_str(archive_fpath),))
        else:
            print('Publishing model')
        print('publish_fpath = %r' % (publish_fpath,))
        ut.copy(archive_fpath, publish_fpath)
Exemplo n.º 20
0
 def __init__(other_cfg, **kwargs):
     super(OtherConfig, other_cfg).__init__(name='other_cfg')
     #other_cfg.thumb_size      = 128
     other_cfg.thumb_size      = 221
     other_cfg.thumb_bare_size = 700
     other_cfg.ranks_lt        = 2
     other_cfg.filter_reviewed = True
     other_cfg.auto_localize   = True
     # maximum number of exemplars per name
     other_cfg.max_exemplars   = 6
     other_cfg.exemplars_per_view  = 2
     other_cfg.prioritized_subset_annots_per_name  = 2
     other_cfg.exemplar_distinctiveness_thresh  = .95
     other_cfg.detect_add_after = 1
     # other_cfg.detect_use_chunks = True
     other_cfg.use_more_special_imagesets = True
     other_cfg.location_for_names = 'IBEIS'
     #other_cfg.location_for_names = 'MUGU'
     other_cfg.smart_enabled = True
     other_cfg.enable_custom_filter = False
     other_cfg.hots_batch_size = 256
     other_cfg.use_augmented_indexer = True
     other_cfg.show_shipped_imagesets = ut.is_developer()
     other_cfg.update(**kwargs)
Exemplo n.º 21
0
    def on_click(self, event):
        aid = self.daid
        qaid = self.qaid
        ibs = self.ibs
        xywh2_ptr = self.xywh2_ptr
        print('[inter] clicked matches')
        if event is None:
            return
        button = event.button
        is_right_click = button == 3

        # Out of axes click
        (x, y, ax) = (event.xdata, event.ydata, event.inaxes)
        if None in [x, y, ax]:
            in_axis = False
            if not is_right_click:
                print('... out of axis')
                self.chipmatch_view()
                viz.draw()
                return
        else:
            in_axis = True

        if in_axis:
            viztype = vh.get_ibsdat(ax, 'viztype', '')
            is_match_type = viztype in ['matches', 'multi_match']
            print('[ir] viztype=%r ' % viztype)
        else:
            is_match_type = False
            viztype = ''

        if is_right_click:
            from ibeis.gui import inspect_gui
            options = []

            if is_match_type:
                options += inspect_gui.get_aidpair_context_menu_options(
                    self.ibs,
                    self.qaid,
                    self.daid,
                    self.cm,
                    qreq_=self.qreq_,
                    #update_callback=self.show_page,
                    #backend_callback=None, aid_list=aid_list)
                )

            options += [
                ('Toggle same_fig', self.toggle_samefig),
                ('Toggle vert', self.toggle_vert),
                ('query last feature', self.query_last_feature),
                ('show each chip', self.show_each_chip),
                ('show each distinctiveness chip',
                 self.show_each_dstncvs_chip),
                ('show each foreground weight chip',
                 self.show_each_fgweight_chip),
                ('show each probchip', self.show_each_probchip),
                ('show coverage', self.show_coverage),
                #('show each probchip', self.query_last_feature),
            ]

            #options.append(('name_interaction', self.name_interaction))
            if self.H1 is not None:
                options.append(('Toggle homog', self.toggle_homog))
            if ut.is_developer():
                options.append(('dev_reload', self.dev_reload))
                options.append(('dev_embed', self.dev_embed))
            #options.append(('cancel', lambda: print('cancel')))
            self.show_popup_menu(options, event)
            return

        if in_axis:
            key = '' if event.key is None else event.key
            print('key=%r ' % key)
            ctrl_down = key.find('control') == 0
            # Click in match axes
            if is_match_type and ctrl_down:
                # Ctrl-Click
                print('.. control click')
                return self.sv_view()
            elif is_match_type:
                if len(self.fm) == 0:
                    print('[inter] no feature matches to click')
                else:
                    # Normal Click
                    # Select nearest feature match to the click
                    kpts1 = ibs.get_annot_kpts([qaid],
                                               config2_=self.query_config2_)[0]
                    kpts2 = ibs.get_annot_kpts([aid],
                                               config2_=self.data_config2_)[0]
                    kpts1_m = kpts1[self.fm.T[0]]
                    kpts2_m = kpts2[self.fm.T[1]]
                    x2, y2, w2, h2 = xywh2_ptr[0]
                    _mx1, _dist1 = ut.nearest_point(x, y, kpts1_m)
                    _mx2, _dist2 = ut.nearest_point(x - x2, y - y2, kpts2_m)
                    mx = _mx1 if _dist1 < _dist2 else _mx2
                    (fx1, fx2) = self.fm[mx]
                    print('... clicked mx=%r' % mx)
                    print('... fx1, fx2 = %r, %r' % (
                        fx1,
                        fx2,
                    ))
                    self.select_ith_match(mx)
            elif viztype in ['warped', 'unwarped']:
                print('clicked at patch')
                ut.print_dict(ph.get_plotdat_dict(ax))
                hs_aid = vh.get_ibsdat(ax, 'aid', None)
                hs_fx = vh.get_ibsdat(ax, 'fx', None)
                #hs_aid = ax.__dict__.get('_hs_aid', None)
                #hs_fx = ax.__dict__.get('_hs_fx', None)
                print('hs_fx = %r' % (hs_fx, ))
                print('hs_aid = %r' % (hs_aid, ))
                if hs_aid is not None and viztype == 'unwarped':
                    ishow_chip(ibs, hs_aid, fx=hs_fx, fnum=df2.next_fnum())
                elif hs_aid is not None and viztype == 'warped':
                    viz.show_keypoint_gradient_orientations(
                        ibs, hs_aid, hs_fx, fnum=df2.next_fnum())
            elif viztype.startswith('colorbar'):
                # Hack to get a specific scoring feature
                sortx = self.fs.argsort()
                idx = np.clip(int(np.round(y * len(sortx))), 0, len(sortx) - 1)
                mx = sortx[idx]
                (fx1, fx2) = self.fm[mx]
                (fx1, fx2) = self.fm[mx]
                print('... selected score at rank idx=%r' % (idx, ))
                print('... selected score with fs=%r' % (self.fs[mx], ))
                print('... resolved to mx=%r' % mx)
                print('... fx1, fx2 = %r, %r' % (
                    fx1,
                    fx2,
                ))
                self.select_ith_match(mx)
            else:
                print('...Unknown viztype: %r' % viztype)
            viz.draw()
Exemplo n.º 22
0
def param_interaction():
    r"""
    CommandLine:
        python -m vtool.test_constrained_matching --test-param_interaction

    Notes:
        python -m vtool.test_constrained_matching --test-param_interaction
        setparam normalizer_mode=nearby
        setparam normalizer_mode=far
        setparam ratio_thresh=.625
        setparam ratio_thresh=.5

        setparam ratio_thresh2=.625
        normalizer_mode=plus

    Example:
        >>> # DISABLE_DOCTEST
        >>> from vtool.test_constrained_matching import *  # NOQA
        >>> # build test data
        >>> # execute function
        >>> testtup = param_interaction()
        >>> # verify results
        >>> result = str(testtup)
        >>> print(result)
    """
    import plottool as pt
    USE_IBEIS = False and ut.is_developer()
    if USE_IBEIS:
        from ibeis.algo.hots import devcases
        index = 2
        fpath1, fpath2, fpath3 = devcases.get_dev_test_fpaths(index)
        testtup1 = testdata_matcher(fpath1, fpath2)
        testtup2 = testdata_matcher(fpath1, fpath3)
    else:
        testtup1 = testdata_matcher('easy1.png', 'easy2.png')
        testtup2 = testdata_matcher('easy1.png', 'hard3.png')
    testtup_list = [testtup1, testtup2]
    simp_list = [SimpleMatcher(testtup) for testtup in testtup_list]
    varied_dict = dict([
        ('sver_xy_thresh', .1),
        ('ratio_thresh', .625),
        ('search_K', 7),
        ('ratio_thresh2', .625),
        ('sver_xy_thresh2', .01),
        ('normalizer_mode', ['nearby', 'far', 'plus'][1]),
        ('match_xy_thresh', .1),
    ])
    cfgdict_list = ut.all_dict_combinations(varied_dict)
    tried_configs = []

    # DEFINE CUSTOM INTRACTIONS
    custom_actions, valid_vizmodes, viz_index_, offset_fnum_ = make_custom_interactions(simp_list)
    # /DEFINE CUSTOM INTRACTIONS

    for cfgdict in ut.InteractiveIter(cfgdict_list,
                                      #default_action='reload',
                                      custom_actions=custom_actions,
                                      wraparound=True):
        for simp in simp_list:
            simp.run_matching(cfgdict=cfgdict)
        vizkey = valid_vizmodes[viz_index_[0]].replace('visualize_', '')
        print('vizkey = %r' % (vizkey,))
        for fnum_, simp in enumerate(simp_list):
            fnum = fnum_ + offset_fnum_[0]
            simp.visualize(vizkey, fnum=fnum)
        tried_configs.append(cfgdict.copy())
        print('Current Config = ')
        print(ut.dict_str(cfgdict))
        pt.present()
        pt.update()
Exemplo n.º 23
0
def build_annot_context_options(
    ibs,
    aid,
    refresh_func=None,
    with_interact_name=True,
    with_interact_chip=True,
    with_interact_image=True,
    config2_=None,
):
    r"""
    Build context options for things that select annotations in the IBEIS gui

    Args:
        ibs (IBEISController):  wbia controller object
        aid (int):  annotation id
        refresh_func (None): (default = None)
        with_interact_name (bool): (default = True)
        with_interact_chip (bool): (default = True)
        with_interact_image (bool): (default = True)
        config2_ (dict): (default = None)

    Returns:
        list: callback_list

    CommandLine:
        python -m wbia.viz.interact.interact_chip --exec-build_annot_context_options

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.viz.interact.interact_chip import *  # NOQA
        >>> import wbia
        >>> ibs = wbia.opendb(defaultdb='testdb1')
        >>> aid = ibs.get_valid_aids()[0]
        >>> refresh_func = None
        >>> with_interact_name = True
        >>> with_interact_chip = True
        >>> with_interact_image = True
        >>> config2_ = None
        >>> callback_list = build_annot_context_options(ibs, aid, refresh_func,
        >>>                                             with_interact_name,
        >>>                                             with_interact_chip,
        >>>                                             with_interact_image,
        >>>                                             config2_)
        >>> result = ('callback_list = %s' % (ut.repr2(callback_list, nl=4),))
        >>> print(result)
    """
    import wbia.guitool as gt

    is_exemplar = ibs.get_annot_exemplar_flags(aid)

    def refresh_wrp(func):
        def _wrp():
            ret = func()
            if refresh_func is None:
                logger.info('no refresh func')
            else:
                logger.info('calling refresh_func=%r' % (refresh_func, ))
                refresh_func()
            return ret

        return _wrp

    def newplot_wrp(func):
        def _wrp():
            import wbia.plottool as pt

            ret = func()
            pt.draw()
            return ret

        return _wrp

    @refresh_wrp
    def toggle_exemplar_func():
        new_flag = not is_exemplar
        logger.info('set_annot_exemplar(%r, %r)' % (aid, new_flag))
        ibs.set_annot_exemplar_flags(aid, new_flag)

    def set_viewpoint_func(view_code):
        # @refresh_wrp()
        def _wrap_view():
            ibs.set_annot_viewpoint_codes([aid], [view_code])
            logger.info('set_annot_yaw(%r, %r)' % (aid, view_code))

        return _wrap_view

    def set_quality_func(qualtext):
        # @refresh_wrp()
        def _wrp_qual():
            ibs.set_annot_quality_texts([aid], [qualtext])
            logger.info('set_annot_quality(%r, %r)' % (aid, qualtext))

        return _wrp_qual

    def set_multiple_func(flag):
        # @refresh_wrp()
        def _wrp():
            ibs.set_annot_multiple([aid], [flag])
            logger.info('set_annot_multiple(%r, %r)' % (aid, flag))

        return _wrp

    # Define popup menu
    callback_list = []

    nid = ibs.get_annot_name_rowids(aid)

    if with_interact_chip:
        callback_list += [(
            'Interact chip',
            partial(ishow_chip, ibs, aid, fnum=None, config2_=config2_),
        )]

    if with_interact_name and not ibs.is_nid_unknown(nid):
        # from wbia.viz.interact import interact_name
        # callback_list.append(
        #    ('Interact name', partial(interact_name.ishow_name, ibs,
        #                                        nid, fnum=None))
        # )
        from wbia.viz import viz_graph2

        nid = ibs.get_annot_nids(aid)
        callback_list.append((
            'New Split Interact (Annots)',
            partial(viz_graph2.make_qt_graph_interface, ibs, nids=[nid]),
        ), )

    if with_interact_image:
        gid = ibs.get_annot_gids(aid)
        from wbia.viz.interact import interact_annotations2

        callback_list.append((
            'Interact image',
            partial(interact_annotations2.ishow_image2, ibs, gid, fnum=None),
        ))

    if True:
        from wbia import viz

        callback_list.append((
            'Show foreground mask',
            newplot_wrp(lambda: viz.show_probability_chip(
                ibs, aid, config2_=config2_)),
        ), )
        callback_list.append((
            'Show foreground mask (blended)',
            newplot_wrp(lambda: viz.show_probability_chip(
                ibs, aid, config2_=config2_, blend=True)),
        ), )

    if True:
        # Edit mask
        callback_list.append((
            'Edit mask',
            partial(ibs.depc_annot.get_property,
                    'annotmask',
                    aid,
                    recompute=True),
        ))

    current_qualtext = ibs.get_annot_quality_texts([aid])[0]
    current_viewcode = ibs.get_annot_viewpoint_code([aid])[0]
    current_multiple = ibs.get_annot_multiple([aid])[0]
    # Nested viewpoints
    callback_list += [
        # ('Set Viewpoint: ' + key, set_viewpoint_func(key))
        (
            'Set &Viewpoint (%s): ' % (current_viewcode, ),
            [(
                '&' + str(count) + ' ' +
                ('*' if current_viewcode == key else '') + key,
                set_viewpoint_func(key),
            ) for count, key in enumerate(ibs.const.VIEW.CODE_TO_NICE.keys(),
                                          start=1)],
        ),
    ]
    # Nested qualities
    callback_list += [
        # ('Set Quality: ' + key, set_quality_func(key))
        (
            'Set &Quality (%s): ' % (current_qualtext, ),
            [(
                '&' + str(count) + ' ' +
                ('*' if current_qualtext == key else '') + '&' + key,
                set_quality_func(key),
            ) for count, key in enumerate(ibs.const.QUALITY_TEXT_TO_INT.keys(),
                                          start=1)],
        ),
    ]

    # TODO: add set species

    callback_list += [
        (
            'Set &multiple: %r' % (not current_multiple),
            set_multiple_func(not current_multiple),
        ),
    ]

    with_tags = True
    if with_tags:
        from wbia import tag_funcs

        case_list = tag_funcs.get_available_annot_tags()
        tags = ibs.get_annot_case_tags([aid])[0]
        tags = [_.lower() for _ in tags]

        case_hotlink_list = gt.make_word_hotlinks(case_list, after_colon=True)

        def _wrap_set_annot_prop(prop, toggle_val):
            if ut.VERBOSE:
                logger.info('[SETTING] Clicked set prop=%r to val=%r' %
                            (prop, toggle_val))
            ibs.set_annot_prop(prop, [aid], [toggle_val])
            if ut.VERBOSE:
                logger.info('[SETTING] done')

        annot_tag_options = []
        for case, case_hotlink in zip(case_list, case_hotlink_list):
            toggle_val = case.lower() not in tags
            fmtstr = 'Mark %s case' if toggle_val else 'Untag %s'
            annot_tag_options += [
                # (fmtstr % (case_hotlink,), lambda:
                # ibs.set_annotmatch_prop(case, _get_annotmatch_rowid(),
                #                        [toggle_val])),
                # (fmtstr % (case_hotlink,), partial(ibs.set_annotmatch_prop,
                # case, [annotmatch_rowid], [toggle_val])),
                (
                    fmtstr % (case_hotlink, ),
                    partial(_wrap_set_annot_prop, case, toggle_val),
                ),
            ]

        callback_list += [
            ('Set Annot Ta&gs', annot_tag_options),
        ]

    callback_list += [('Remove name',
                       lambda: ibs.set_annot_name_rowids([aid], [-aid]))]

    def _setname_callback():
        import wbia.guitool as gt

        name = ibs.get_annot_name_texts([aid])[0]
        newname = gt.user_input(title='edit name', msg=name, text=name)
        if newname is not None:
            logger.info('[ctx] _setname_callback aid=%r resp=%r' %
                        (aid, newname))
            ibs.set_annot_name_texts([aid], [newname])

    callback_list += [('Set name', _setname_callback)]

    callback_list += [
        (
            'Unset as e&xemplar' if is_exemplar else 'Set as e&xemplar',
            toggle_exemplar_func,
        ),
    ]

    annot_info = ibs.get_annot_info(aid,
                                    default=True,
                                    gname=False,
                                    name=False,
                                    notes=False,
                                    exemplar=False)

    def print_annot_info():
        logger.info('[interact_chip] Annotation Info = ' +
                    ut.repr2(annot_info, nl=4))
        logger.info('config2_ = %r' % (config2_, ))
        if config2_ is not None:
            logger.info('config2_.__dict__ = %s' %
                        (ut.repr3(config2_.__dict__), ))

    dev_callback_list = []

    def dev_edit_annot_tags():
        logger.info('ibs = %r' % (ibs, ))
        text = ibs.get_annot_tag_text([aid])[0]
        resp = gt.user_input(title='edit tags', msg=text, text=text)
        if resp is not None:
            try:
                logger.info('resp = %r' % (resp, ))
                logger.info('[ctx] set_annot_tag_text aid=%r resp=%r' %
                            (aid, resp))
                ibs.set_annot_tag_text(aid, resp)
                new_text = ibs.get_annot_tag_text([aid])[0]
                logger.info('new_text = %r' % (new_text, ))
                assert new_text == resp, 'should have had text change'
            except Exception as ex:
                ut.printex(ex, 'error in dev edit tags')
                raise

    def dev_set_annot_species():
        text = ibs.get_annot_species([aid])[0]
        resp = gt.user_input(title='edit species', msg=text, text=text)
        if resp is not None:
            try:
                logger.info('resp = %r' % (resp, ))
                logger.info('[ctx] set_annot_tag_text aid=%r resp=%r' %
                            (aid, resp))
                ibs.set_annot_species(aid, resp)
                new_text = ibs.get_annot_species_texts([aid])[0]
                logger.info('new_text = %r' % (new_text, ))
                assert new_text == resp, 'should have had text change'
            except Exception as ex:
                ut.printex(ex, 'error in dev edit species')
                raise

    dev_callback_list += [
        ('dev Edit Annot Ta&gs', dev_edit_annot_tags),
        ('dev print annot info', print_annot_info),
        ('dev refresh', pt.update),
    ]

    if ut.is_developer():

        def dev_debug():
            logger.info('aid = %r' % (aid, ))
            logger.info('config2_ = %r' % (config2_, ))

        def dev_embed(ibs=ibs, aid=aid, config2_=config2_):
            # import wbia.plottool as pt
            # pt.plt.ioff()
            # TODO need to disable matplotlib callbacks?
            # Causes can't re-enter readline error
            ut.embed()
            # pt.plt.ion()
            pass

        dev_callback_list += [
            ('dev chip context embed', dev_embed),
            ('dev chip context debug', dev_debug),
        ]
    if len(dev_callback_list) > 0:
        callback_list += [('Dev', dev_callback_list)]
    return callback_list
Exemplo n.º 24
0
    def append_case(case, testtup):
        print('APPENDED NEW TESTCASE: case=%r' % (case,))
        print('* testup = %r' % (testtup,))
        print('* vuuid = %r' % (ibs_gt.get_annot_visual_uuids(testtup.qaid_t),))
        if ut.get_argflag('--interupt-case') and case in [VSMANY_WINS, VSMANY_DOMINATES]:
            incinfo['interactive'] = True
            incinfo['use_oracle'] = False
            incinfo['STOP'] = True
            if ut.is_developer():
                import plottool as pt  # NOQA
                IPYTHON_COMMANDS = """
                >>> %pylab qt4
                >>> from ibeis.viz.interact import interact_matches  # NOQA
                >>> #qres_vsmany = ut.search_stack_for_localvar('qres_vsmany')
                >>> ibs        = ut.search_stack_for_localvar('ibs')
                >>> daids      = ut.search_stack_for_localvar('daids')
                >>> qnid_t     = ut.search_stack_for_localvar('qnid_t')
                >>> qres_vsone = ut.search_stack_for_localvar('qres_vsone')
                >>> all_nids_t = ut.search_stack_for_localvar('all_nids_t')
                >>> # Find index in daids of correct matches
                >>> cm = qres_vsone
                >>> correct_indices = np.where(np.array(all_nids_t) == qnid_t)[0]
                >>> correct_aids2 = ut.take(daids, correct_indices)
                >>> qaid = cm.qaid
                >>> aid = correct_aids2[0]
                >>> # Report visual uuid for inclusion or exclusion in script
                >>> print(ibs.get_annot_visual_uuids([qaid, aid]))

                >>> # Feature match things
                >>> print('cm.filtkey_list = %r' % (cm.filtkey_list,))
                >>> fm  = cm.aid2_fm[aid]
                >>> fs  = cm.aid2_fs[aid]
                >>> fsv = cm.aid2_fsv[aid]
                >>> mx = 2
                >>> qfx, dfx = fm[mx]
                >>> fsv_single = fsv[mx]
                >>> fs_single = fs[mx]
                >>> # check featweights
                >>> data_featweights = ibs.get_annot_fgweights([aid])[0]
                >>> data_featweights[dfx]
                >>> fnum = pt.next_fnum()
                >>> bad_aid = cm.get_top_aids()[0]
                >>> #match_interaction_good = interact_matches.MatchInteraction(ibs, cm, aid, annot_mode=1)
                >>> #match_interaction_bad = interact_matches.MatchInteraction(ibs, cm, bad_aid)
                >>> match_interaction_good = cm.ishow_matches(ibs, aid, annot_mode=1, fnum=1)
                >>> match_interaction_bad = cm.ishow_matches(ibs, bad_aid, annot_mode=1, fnum=2)
                >>> match_interaction = match_interaction_good
                >>> self = match_interaction
                >>> self.select_ith_match(mx)
                >>> #impossible_to_match = len(correct_indices) > 0
                """
                y = """
                >>> from os.path import exists
                >>> import vtool as vt
                >>> import vtool.patch as vtpatch
                >>> import vtool.image as vtimage  # NOQA
                >>> chip_list = ibs.get_annot_chips([aid])
                >>> kpts_list = ibs.get_annot_kpts([aid])
                >>> probchip_fpath_list = ibs.get_probchip_fpath(aid)
                >>> probchip_list = [vt.imread(fpath, grayscale=True) if exists(fpath) else None for fpath in probchip_fpath_list]
                >>> kpts  = kpts_list[0]
                >>> probchip = probchip_list[0]
                >>> kp = kpts[dfx]
                >>> patch  = vt.get_warped_patch(probchip, kp)[0].astype(np.float32) / 255.0
                >>> fnum2 = pt.next_fnum()
                >>> pt.figure(fnum2, pnum=(1, 2, 1), doclf=True, docla=True)
                >>> pt.imshow(probchip)
                >>> pt.draw_kpts2([kp])
                >>> pt.figure(fnum2, pnum=(1, 2, 2))
                >>> pt.imshow(patch * 255)
                >>> pt.update()
                >>> vt.gaussian_average_patch(patch)
                >>> cm.ishow_top(ibs, annot_mode=1)
                """
                y
                ut.set_clipboard(IPYTHON_COMMANDS)
                #ut.spawn_delayed_ipython_paste()
                ut.embed(remove_pyqt_hook=False)
                IPYTHON_COMMANDS

        testcases[case].append(testtup)
Exemplo n.º 25
0
def build_annot_context_options(ibs, aid, refresh_func=None,
                                 with_interact_name=True,
                                 with_interact_chip=True,
                                 with_interact_image=True, config2_=None):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        aid (int):  annotation id
        refresh_func (None): (default = None)
        with_interact_name (bool): (default = True)
        with_interact_chip (bool): (default = True)
        with_interact_image (bool): (default = True)
        config2_ (dict): (default = None)

    Returns:
        list: callback_list

    CommandLine:
        python -m ibeis.viz.interact.interact_chip --exec-build_annot_context_options

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_chip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb(defaultdb='testdb1')
        >>> aid = ibs.get_valid_aids()[0]
        >>> refresh_func = None
        >>> with_interact_name = True
        >>> with_interact_chip = True
        >>> with_interact_image = True
        >>> config2_ = None
        >>> callback_list = build_annot_context_options(ibs, aid, refresh_func,
        >>>                                             with_interact_name,
        >>>                                             with_interact_chip,
        >>>                                             with_interact_image,
        >>>                                             config2_)
        >>> result = ('callback_list = %s' % (ut.list_str(callback_list, nl=4),))
        >>> print(result)
    """
    import guitool
    is_exemplar = ibs.get_annot_exemplar_flags(aid)

    def refresh_wrp(func):
        def _wrp():
            ret = func()
            if refresh_func is None:
                print('no refresh func')
            else:
                print('calling refresh_func=%r' % (refresh_func,))
                refresh_func()
            return ret
        return _wrp

    @refresh_wrp
    def toggle_exemplar_func():
        new_flag = not is_exemplar
        print('set_annot_exemplar(%r, %r)' % (aid, new_flag))
        ibs.set_annot_exemplar_flags(aid, new_flag)
    def set_yaw_func(yawtext):
        #@refresh_wrp()
        def _wrap_yaw():
            ibs.set_annot_yaw_texts([aid], [yawtext])
            print('set_annot_yaw(%r, %r)' % (aid, yawtext))
        return _wrap_yaw
    def set_quality_func(qualtext):
        #@refresh_wrp()
        def _wrp_qual():
            ibs.set_annot_quality_texts([aid], [qualtext])
            print('set_annot_quality(%r, %r)' % (aid, qualtext))
        return _wrp_qual
    # Define popup menu
    callback_list = []

    nid = ibs.get_annot_name_rowids(aid)

    if with_interact_chip:
        callback_list += [
            ('Interact chip',
             partial(
                 ishow_chip, ibs, aid, fnum=None, config2_=config2_))
        ]

    if with_interact_name and not ibs.is_nid_unknown(nid):
        from ibeis.viz.interact import interact_name
        callback_list.append(
            ('Interact name', partial(interact_name.ishow_name, ibs,
                                                nid, fnum=None))
        )
        from ibeis.viz import viz_graph
        callback_list.append(
            ('Interact name graph',
             partial(viz_graph.make_name_graph_interaction,
                               ibs, nids=None, aids=[aid])),
        )

    if with_interact_image:
        gid = ibs.get_annot_gids(aid)
        from ibeis.viz.interact import interact_annotations2
        callback_list.append(
            ('Interact image',
             partial(
                 interact_annotations2.ishow_image2, ibs, gid, fnum=None))
        )

    if True:
        from ibeis import viz
        callback_list.append(
            ('View detection chip (probability) [dev]',
             refresh_wrp(lambda: viz.show_probability_chip(
                 ibs, aid, config2_=config2_))),
        )

    current_qualtext = ibs.get_annot_quality_texts([aid])[0]
    current_yawtext = ibs.get_annot_yaw_texts([aid])[0]
    # Nested viewpoints
    callback_list += [
        #('Set Viewpoint: ' + key, set_yaw_func(key))
        ('Set &Viewpoint: ',  [
            ('&' + str(count) + ' ' +
             ('*' if current_yawtext == key else '') + key,
             set_yaw_func(key))
            for count, key in
            enumerate(six.iterkeys(const.VIEWTEXT_TO_YAW_RADIANS), start=1)
        ]),
    ]
    # Nested qualities
    callback_list += [
        #('Set Quality: ' + key, set_quality_func(key))
        ('Set &Quality: ',  [
            ('&' + str(count) + ' ' + ('*' if current_qualtext == key else '') +
             '&' + key,
             set_quality_func(key))
            for count, key in
            enumerate(six.iterkeys(const.QUALITY_TEXT_TO_INT), start=1)
        ]),
    ]

    with_tags = True
    if with_tags:
        from ibeis import tag_funcs
        case_list = tag_funcs.get_available_annot_tags()
        tags = ibs.get_annot_case_tags([aid])[0]
        tags = [_.lower() for _ in tags]

        case_hotlink_list = guitool.make_word_hotlinks(case_list,
                                                       after_colon=True)

        def _wrap_set_annot_prop(prop, toggle_val):
            if ut.VERBOSE:
                print('[SETTING] Clicked set prop=%r to val=%r' %
                      (prop, toggle_val,))
            ibs.set_annot_prop(prop, [aid], [toggle_val])
            if ut.VERBOSE:
                print('[SETTING] done')

        annot_tag_options = []
        for case, case_hotlink in zip(case_list, case_hotlink_list):
            toggle_val = case.lower() not in tags
            fmtstr = 'Mark %s case' if toggle_val else 'Untag %s'
            annot_tag_options += [
                #(fmtstr % (case_hotlink,), lambda:
                #ibs.set_annotmatch_prop(case, _get_annotmatch_rowid(),
                #                        [toggle_val])),
                #(fmtstr % (case_hotlink,), partial(ibs.set_annotmatch_prop,
                #case, [annotmatch_rowid], [toggle_val])),
                (fmtstr % (case_hotlink,), partial(_wrap_set_annot_prop, case,
                                                   toggle_val)),
            ]

        callback_list += [
            ('Set Annot Ta&gs', annot_tag_options),
        ]

    callback_list += [
        ('Unset as e&xemplar' if is_exemplar else 'Set as e&xemplar',
         toggle_exemplar_func),
    ]

    annot_info = ibs.get_annot_info(
        aid, default=True, gname=False, name=False, notes=False,
        exemplar=False)

    def print_annot_info():
        print('[interact_chip] Annotation Info = ' + ut.obj_str(annot_info, nl=4))

    callback_list += [
        ('dev print annot info', print_annot_info),
        ('dev refresh', pt.update),
    ]

    if ut.is_developer():
        def dev_debug():
            print('aid = %r' % (aid,))
            print('config2_ = %r' % (config2_,))
        def dev_embed(ibs=ibs, aid=aid, config2_=config2_):
            ut.embed()
            pass
        callback_list += [
            ('dev chip context embed', dev_embed),
            ('dev chip context debug', dev_debug),
        ]
    return callback_list
Exemplo n.º 26
0
def compute_vocab(depc, fid_list, config):
    r"""
    Depcache method for computing a new visual vocab

    CommandLine:
        python -m wbia.core_annots --exec-compute_neighbor_index --show
        python -m wbia show_depc_annot_table_input --show --tablename=neighbor_index

        python -m wbia.algo.smk.vocab_indexer --exec-compute_vocab:0
        python -m wbia.algo.smk.vocab_indexer --exec-compute_vocab:1

        # FIXME make util_tests register
        python -m wbia.algo.smk.vocab_indexer compute_vocab:0

    Ignore:
        >>> # Lev Oxford Debug Example
        >>> import wbia
        >>> ibs = wbia.opendb('Oxford')
        >>> depc = ibs.depc
        >>> table = depc['vocab']
        >>> # Check what currently exists in vocab table
        >>> table.print_configs()
        >>> table.print_table()
        >>> table.print_internal_info()
        >>> # Grab aids used to compute vocab
        >>> from wbia.expt.experiment_helpers import get_annotcfg_list
        >>> expanded_aids_list = get_annotcfg_list(ibs, ['oxford'])[1]
        >>> qaids, daids = expanded_aids_list[0]
        >>> vocab_aids = daids
        >>> config = {'num_words': 64000}
        >>> exists = depc.check_rowids('vocab', [vocab_aids], config=config)
        >>> print('exists = %r' % (exists,))
        >>> vocab_rowid = depc.get_rowids('vocab', [vocab_aids], config=config)[0]
        >>> print('vocab_rowid = %r' % (vocab_rowid,))
        >>> vocab = table.get_row_data([vocab_rowid], 'words')[0]
        >>> print('vocab = %r' % (vocab,))

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.algo.smk.vocab_indexer import *  # NOQA
        >>> # Test depcache access
        >>> import wbia
        >>> ibs, aid_list = wbia.testdata_aids('testdb1')
        >>> depc = ibs.depc_annot
        >>> input_tuple = [aid_list]
        >>> rowid_kw = {}
        >>> tablename = 'vocab'
        >>> vocabid_list = depc.get_rowids(tablename, input_tuple, **rowid_kw)
        >>> vocab = depc.get(tablename, input_tuple, 'words')[0]
        >>> assert vocab.wordflann is not None
        >>> assert vocab.wordflann._FLANN__curindex_data is not None
        >>> assert vocab.wordflann._FLANN__curindex_data is vocab.wx_to_word

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.algo.smk.vocab_indexer import *  # NOQA
        >>> import wbia
        >>> ibs, aid_list = wbia.testdata_aids('testdb1')
        >>> depc = ibs.depc_annot
        >>> fid_list = depc.get_rowids('feat', aid_list)
        >>> config = VocabConfig()
        >>> vocab, train_vecs = ut.exec_func_src(compute_vocab, keys=['vocab', 'train_vecs'])
        >>> idx_to_vec = depc.d.get_feat_vecs(aid_list)[0]
        >>> self = vocab
        >>> ut.quit_if_noshow()
        >>> data = train_vecs
        >>> centroids = vocab.wx_to_word
        >>> import wbia.plottool as pt
        >>> vt.plot_centroids(data, centroids, num_pca_dims=2)
        >>> ut.show_if_requested()
        >>> #config = ibs.depc_annot['vocab'].configclass()

    """
    logger.info('[IBEIS] COMPUTE_VOCAB:')
    vecs_list = depc.get_native('feat', fid_list, 'vecs')
    train_vecs = np.vstack(vecs_list).astype(np.float32)
    num_words = config['num_words']
    logger.info(
        '[smk_index] Train Vocab(nWords=%d) using %d annots and %d descriptors'
        % (num_words, len(fid_list), len(train_vecs)))
    if config['algorithm'] == 'kdtree':
        flann_params = vt.get_flann_params(random_seed=42)
        kwds = dict(max_iters=20, flann_params=flann_params)
        words = vt.akmeans(train_vecs, num_words, **kwds)
    elif config['algorithm'] == 'minibatch':
        logger.info('Using minibatch kmeans')
        import sklearn.cluster

        rng = np.random.RandomState(config['random_seed'])
        n_init = config['n_init']
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            init_size = int(num_words * 4)
            batch_size = 1000
            n_batches = ut.get_num_chunks(train_vecs.shape[0], batch_size)
            minibatch_params = dict(
                n_clusters=num_words,
                init='k-means++',
                init_size=init_size,
                n_init=n_init,
                max_iter=30000 // n_batches,
                batch_size=batch_size,
                tol=0.0,
                max_no_improvement=10,
                reassignment_ratio=0.01,
            )
            logger.info('minibatch_params = %s' %
                        (ut.repr4(minibatch_params), ))
            clusterer = sklearn.cluster.MiniBatchKMeans(compute_labels=False,
                                                        random_state=rng,
                                                        verbose=2,
                                                        **minibatch_params)
            try:
                clusterer.fit(train_vecs)
            except (Exception, KeyboardInterrupt) as ex:
                ut.printex(ex, tb=True)
                if ut.is_developer():
                    ut.embed()
                else:
                    raise
        words = clusterer.cluster_centers_
        logger.info('Finished clustering')
    # if False:
    #     flann_params['checks'] = 64
    #     flann_params['trees'] = 4
    #     num_words = 128
    #     centroids = vt.initialize_centroids(num_words, train_vecs, 'akmeans++')
    #     words, hist = vt.akmeans_iterations(
    #         train_vecs, centroids, max_iters=1000, monitor=True,
    #         flann_params=flann_params)

    logger.info('Constructing vocab')
    vocab = VisualVocab(words)
    logger.info('Building vocab index')
    vocab.build()
    logger.info('Returning vocab')
    return (vocab, )
Exemplo n.º 27
0
    def plot_chip(self, aid, nRows, nCols, px, fulldraw=True, **kwargs):
        """ Plots an individual chip in a subaxis """
        ibs = self.ibs
        if aid in [self.aid1, self.aid2]:
            # Bold color for the matching chips
            lw = 5
            text_color = np.array((135, 206, 235, 255)) / 255.0
        else:
            lw = 2
            text_color = None

        pnum = (nRows, nCols, px)
        if not fulldraw:
            # not doing full draw so we have to clear any axes
            # that are here already manually
            ax = self.fig.add_subplot(*pnum)
            self.clear_parent_axes(ax)
            #ut.embed()
            #print(subax)

        viz_chip_kw = {
            'fnum': self.fnum,
            'pnum': pnum,
            'nokpts': True,
            'show_name': True,
            'show_gname': False,
            'show_aidstr': True,
            'notitle': True,
            'show_num_gt': False,
            'text_color': text_color,
        }
        if False and ut.is_developer():
            enable_chip_title_prefix = True
            viz_chip_kw.update({
                'enable_chip_title_prefix': enable_chip_title_prefix,
                'show_name': True,
                'show_aidstr': True,
                'show_viewcode': True,
                'show_num_gt': True,
                'show_quality_text': True,
            })

        viz_chip.show_chip(ibs, aid, **viz_chip_kw)
        ax = pt.gca()
        pt.draw_border(ax, color=kwargs.get('color'), lw=lw)
        if kwargs.get('make_buttons', True):
            #divider = pt.ensure_divider(ax)
            butkw = {
                #'divider': divider,
                'ax': ax,
                'size': '13%'
                #'size': '15%'
            }
        # Chip matching/naming options
        nid = ibs.get_annot_name_rowids(aid)
        annotation_unknown = ibs.is_nid_unknown([nid])[0]
        if not annotation_unknown:
            # remove name
            callback = functools.partial(self.unname_annotation, aid)
            self.append_button('remove name (' + ibs.get_name_texts(nid) + ')',
                               callback=callback,
                               **butkw)
        else:
            # new name
            callback = functools.partial(self.mark_annotation_as_new_name, aid)
            self.append_button('mark as new name', callback=callback, **butkw)
        if nid != self.nid2 and not ibs.is_nid_unknown(
            [self.nid2])[0] and not self.is_split_case:
            # match to nid2
            callback = functools.partial(self.rename_annotation, aid,
                                         self.nid2)
            text = 'match to name2: ' + ibs.get_name_texts(self.nid2)
            self.append_button(text, callback=callback, **butkw)
        if nid != self.nid1 and not ibs.is_nid_unknown([self.nid1])[0]:
            # match to nid1
            callback = functools.partial(self.rename_annotation, aid,
                                         self.nid1)
            text = 'match to name1: ' + ibs.get_name_texts(self.nid1)
            self.append_button(text, callback=callback, **butkw)

        other_nid_list = self.get_other_nids()
        for other_nid in other_nid_list:
            if other_nid == nid:
                continue
            # rename nid2
            callback = functools.partial(self.rename_annotation, aid,
                                         other_nid)
            text = 'match to: ' + ibs.get_name_texts(other_nid)
            self.append_button(text, callback=callback, **butkw)
        return ax
Exemplo n.º 28
0
def build_annot_context_options(ibs, aid, refresh_func=None,
                                 with_interact_name=True,
                                 with_interact_chip=True,
                                 with_interact_image=True, config2_=None):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        aid (int):  annotation id
        refresh_func (None): (default = None)
        with_interact_name (bool): (default = True)
        with_interact_chip (bool): (default = True)
        with_interact_image (bool): (default = True)
        config2_ (dict): (default = None)

    Returns:
        list: callback_list

    CommandLine:
        python -m ibeis.viz.interact.interact_chip --exec-build_annot_context_options

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_chip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb(defaultdb='testdb1')
        >>> aid = ibs.get_valid_aids()[0]
        >>> refresh_func = None
        >>> with_interact_name = True
        >>> with_interact_chip = True
        >>> with_interact_image = True
        >>> config2_ = None
        >>> callback_list = build_annot_context_options(ibs, aid, refresh_func,
        >>>                                             with_interact_name,
        >>>                                             with_interact_chip,
        >>>                                             with_interact_image,
        >>>                                             config2_)
        >>> result = ('callback_list = %s' % (ut.list_str(callback_list, nl=4),))
        >>> print(result)
    """
    import guitool
    is_exemplar = ibs.get_annot_exemplar_flags(aid)

    def refresh_wrp(func):
        def _wrp():
            ret = func()
            if refresh_func is None:
                print('no refresh func')
            else:
                print('calling refresh_func=%r' % (refresh_func,))
                refresh_func()
            return ret
        return _wrp

    def newplot_wrp(func):
        def _wrp():
            import plottool as pt
            ret = func()
            pt.draw()
            return ret
        return _wrp

    @refresh_wrp
    def toggle_exemplar_func():
        new_flag = not is_exemplar
        print('set_annot_exemplar(%r, %r)' % (aid, new_flag))
        ibs.set_annot_exemplar_flags(aid, new_flag)
    def set_yaw_func(yawtext):
        #@refresh_wrp()
        def _wrap_yaw():
            ibs.set_annot_yaw_texts([aid], [yawtext])
            print('set_annot_yaw(%r, %r)' % (aid, yawtext))
        return _wrap_yaw
    def set_quality_func(qualtext):
        #@refresh_wrp()
        def _wrp_qual():
            ibs.set_annot_quality_texts([aid], [qualtext])
            print('set_annot_quality(%r, %r)' % (aid, qualtext))
        return _wrp_qual
    # Define popup menu
    callback_list = []

    nid = ibs.get_annot_name_rowids(aid)

    if with_interact_chip:
        callback_list += [
            ('Interact chip',
             partial(
                 ishow_chip, ibs, aid, fnum=None, config2_=config2_))
        ]

    if with_interact_name and not ibs.is_nid_unknown(nid):
        from ibeis.viz.interact import interact_name
        callback_list.append(
            ('Interact name', partial(interact_name.ishow_name, ibs,
                                                nid, fnum=None))
        )
        from ibeis.viz import viz_graph
        callback_list.append(
            ('Interact name graph',
             partial(viz_graph.make_name_graph_interaction,
                               ibs, nids=None, aids=[aid])),
        )

    if with_interact_image:
        gid = ibs.get_annot_gids(aid)
        from ibeis.viz.interact import interact_annotations2
        callback_list.append(
            ('Interact image',
             partial(
                 interact_annotations2.ishow_image2, ibs, gid, fnum=None))
        )

    if True:
        from ibeis import viz
        callback_list.append(
            ('Show foreground mask',
             newplot_wrp(lambda: viz.show_probability_chip(
                 ibs, aid, config2_=config2_))),
        )
        callback_list.append(
            ('Show foreground mask (blended)',
             newplot_wrp(lambda: viz.show_probability_chip(
                 ibs, aid, config2_=config2_, blend=True))),
        )

    if True:
        # Edit mask
        callback_list.append(
            ('Edit mask',
             partial(ibs.depc_annot.get_property, 'annotmask', aid, recompute=True))
        )

    current_qualtext = ibs.get_annot_quality_texts([aid])[0]
    current_yawtext = ibs.get_annot_yaw_texts([aid])[0]
    # Nested viewpoints
    callback_list += [
        #('Set Viewpoint: ' + key, set_yaw_func(key))
        ('Set &Viewpoint: ',  [
            ('&' + str(count) + ' ' +
             ('*' if current_yawtext == key else '') + key,
             set_yaw_func(key))
            for count, key in
            enumerate(six.iterkeys(const.VIEWTEXT_TO_YAW_RADIANS), start=1)
        ]),
    ]
    # Nested qualities
    callback_list += [
        #('Set Quality: ' + key, set_quality_func(key))
        ('Set &Quality: ',  [
            ('&' + str(count) + ' ' + ('*' if current_qualtext == key else '') +
             '&' + key,
             set_quality_func(key))
            for count, key in
            enumerate(six.iterkeys(const.QUALITY_TEXT_TO_INT), start=1)
        ]),
    ]

    with_tags = True
    if with_tags:
        from ibeis import tag_funcs
        case_list = tag_funcs.get_available_annot_tags()
        tags = ibs.get_annot_case_tags([aid])[0]
        tags = [_.lower() for _ in tags]

        case_hotlink_list = guitool.make_word_hotlinks(case_list,
                                                       after_colon=True)

        def _wrap_set_annot_prop(prop, toggle_val):
            if ut.VERBOSE:
                print('[SETTING] Clicked set prop=%r to val=%r' %
                      (prop, toggle_val,))
            ibs.set_annot_prop(prop, [aid], [toggle_val])
            if ut.VERBOSE:
                print('[SETTING] done')

        annot_tag_options = []
        for case, case_hotlink in zip(case_list, case_hotlink_list):
            toggle_val = case.lower() not in tags
            fmtstr = 'Mark %s case' if toggle_val else 'Untag %s'
            annot_tag_options += [
                #(fmtstr % (case_hotlink,), lambda:
                #ibs.set_annotmatch_prop(case, _get_annotmatch_rowid(),
                #                        [toggle_val])),
                #(fmtstr % (case_hotlink,), partial(ibs.set_annotmatch_prop,
                #case, [annotmatch_rowid], [toggle_val])),
                (fmtstr % (case_hotlink,), partial(_wrap_set_annot_prop, case,
                                                   toggle_val)),
            ]

        callback_list += [
            ('Set Annot Ta&gs', annot_tag_options),
        ]

    callback_list += [
        ('Remove name', lambda: ibs.set_annot_name_rowids([aid], [-aid]))
    ]

    callback_list += [
        ('Unset as e&xemplar' if is_exemplar else 'Set as e&xemplar',
         toggle_exemplar_func),
    ]

    annot_info = ibs.get_annot_info(
        aid, default=True, gname=False, name=False, notes=False,
        exemplar=False)

    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__),))

    callback_list += [
        ('dev print annot info', print_annot_info),
        ('dev refresh', pt.update),
    ]

    if ut.is_developer():
        def dev_debug():
            print('aid = %r' % (aid,))
            print('config2_ = %r' % (config2_,))
        def dev_embed(ibs=ibs, aid=aid, config2_=config2_):
            #import plottool as pt
            #pt.plt.ioff()
            # TODO need to disable matplotlib callbacks?
            # Causes can't re-enter readline error
            ut.embed()
            #pt.plt.ion()
            pass
        callback_list += [
            ('dev chip context embed', dev_embed),
            ('dev chip context debug', dev_debug),
        ]
    return callback_list
Exemplo n.º 29
0
    def plot_chip(self, aid, nRows, nCols, px, **kwargs):
        """ Plots an individual chip in a subaxis """
        ibs = self.ibs
        enable_chip_title_prefix = ut.is_developer()
        #enable_chip_title_prefix = False
        if aid in self.comp_aids:
            score = self.cm.get_annot_scores([aid])[0]
            rawscore = self.cm.get_annot_scores([aid])[0]
            title_suf = kwargs.get('title_suffix', '')
            if score != rawscore:
                if score is None:
                    title_suf += '\n score=____'
                else:
                    title_suf += '\n score=%0.2f' % score
            title_suf += '\n rawscore=%0.2f' % rawscore
        else:
            title_suf = kwargs.get('title_suffix', '')
            if enable_chip_title_prefix:
                title_suf = '\n' + title_suf

        #nid = ibs.get_annot_name_rowids(aid)
        viz_chip_kw = {
            'fnum': self.fnum,
            'pnum': (nRows, nCols, px),
            'nokpts': True,
            'show_gname': False,
            'show_exemplar': False,
            'show_num_gt': False,
            'show_gname': False,
            'title_suffix': title_suf,
            # 'text_color': kwargs.get('color'),
            ###
            #'show_name': False,
            #'show_aidstr': False,
            'enable_chip_title_prefix': enable_chip_title_prefix,
            'show_name': True,
            'show_aidstr': True,
            'show_yawtext': True,
            'show_quality_text': True,
        }

        viz_chip.show_chip(ibs, aid, **viz_chip_kw)
        ax = pt.gca()
        if kwargs.get('make_buttons', True):
            divider = pt.ensure_divider(ax)
            butkw = {'divider': divider, 'size': '13%'}

        self.aid2_ax = {}
        self.aid2_border = {}

        if aid in self.comp_aids:
            callback = partial(self.select, aid)
            self.append_button('Select This Animal',
                               callback=callback,
                               **butkw)
            #Hack to toggle colors
            if aid in self.aid_checkbox_states:
                #If we are selecting it, then make it green, otherwise change it back to grey
                if self.aid_checkbox_states[aid]:
                    border = pt.draw_border(ax, color=(0, 1, 0), lw=4)
                else:
                    border = pt.draw_border(ax, color=(.7, .7, .7), lw=4)
                self.aid2_border[aid] = border
            else:
                self.aid_checkbox_states[aid] = False
            self.append_button('Examine',
                               callback=partial(self.examine, aid),
                               **butkw)
Exemplo n.º 30
0
def param_interaction():
    r"""
    CommandLine:
        python -m vtool.test_constrained_matching --test-param_interaction

    Notes:
        python -m vtool.test_constrained_matching --test-param_interaction
        setparam normalizer_mode=nearby
        setparam normalizer_mode=far
        setparam ratio_thresh=.625
        setparam ratio_thresh=.5

        setparam ratio_thresh2=.625
        normalizer_mode=plus

    Example:
        >>> # DISABLE_DOCTEST
        >>> from vtool.test_constrained_matching import *  # NOQA
        >>> # build test data
        >>> # execute function
        >>> testtup = param_interaction()
        >>> # verify results
        >>> result = str(testtup)
        >>> print(result)
    """
    import plottool as pt
    USE_IBEIS = False and ut.is_developer()
    if USE_IBEIS:
        from ibeis.algo.hots import devcases
        index = 2
        fpath1, fpath2, fpath3 = devcases.get_dev_test_fpaths(index)
        testtup1 = testdata_matcher(fpath1, fpath2)
        testtup2 = testdata_matcher(fpath1, fpath3)
    else:
        testtup1 = testdata_matcher('easy1.png', 'easy2.png')
        testtup2 = testdata_matcher('easy1.png', 'hard3.png')
    testtup_list = [testtup1, testtup2]
    simp_list = [SimpleMatcher(testtup) for testtup in testtup_list]
    varied_dict = dict([
        ('sver_xy_thresh', .1),
        ('ratio_thresh', .625),
        ('search_K', 7),
        ('ratio_thresh2', .625),
        ('sver_xy_thresh2', .01),
        ('normalizer_mode', ['nearby', 'far', 'plus'][1]),
        ('match_xy_thresh', .1),
    ])
    cfgdict_list = ut.all_dict_combinations(varied_dict)
    tried_configs = []

    # DEFINE CUSTOM INTRACTIONS
    custom_actions, valid_vizmodes, viz_index_, offset_fnum_ = make_custom_interactions(
        simp_list)
    # /DEFINE CUSTOM INTRACTIONS

    for cfgdict in ut.InteractiveIter(
            cfgdict_list,
            #default_action='reload',
            custom_actions=custom_actions,
            wraparound=True):
        for simp in simp_list:
            simp.run_matching(cfgdict=cfgdict)
        vizkey = valid_vizmodes[viz_index_[0]].replace('visualize_', '')
        print('vizkey = %r' % (vizkey, ))
        for fnum_, simp in enumerate(simp_list):
            fnum = fnum_ + offset_fnum_[0]
            simp.visualize(vizkey, fnum=fnum)
        tried_configs.append(cfgdict.copy())
        print('Current Config = ')
        print(ut.dict_str(cfgdict))
        pt.present()
        pt.update()
Exemplo n.º 31
0
def get_aidpair_context_menu_options(ibs,
                                     aid1,
                                     aid2,
                                     cm,
                                     qreq_=None,
                                     aid_list=None,
                                     **kwargs):
    """ assert that the ampersand cannot have duplicate keys

    Args:
        ibs (wbia.IBEISController):  wbia controller object
        aid1 (int):  annotation id
        aid2 (int):  annotation id
        cm (wbia.ChipMatch):  object of feature correspondences and scores
        qreq_ (wbia.QueryRequest):  query request object with hyper-parameters(default = None)
        aid_list (list):  list of annotation rowids(default = None)

    Returns:
        list: options

    CommandLine:
        python -m wbia.gui.inspect_gui --exec-get_aidpair_context_menu_options
        python -m wbia.gui.inspect_gui --exec-get_aidpair_context_menu_options --verbose
        python -m wbia.gui.inspect_gui --exec-get_aidpair_context_menu_options --verbose -a timecontrolled -t invarbest --db PZ_Master1  --qaid 574

        # Other scripts that call this one;w
        python -m wbia.dev -e cases --db PZ_Master1  -a timectrl -t best --filt :sortdsc=gfscore,fail=True,min_gtscore=.0001 --show
        python -m wbia.dev -e cases --db PZ_MTEST  -a timectrl -t best --filt :sortdsc=gfscore,fail=True,min_gtscore=.0001 --show

    Example:
        >>> # ENABLE_DOCTEST
        >>> from wbia.gui.inspect_gui import *  # NOQA
        >>> import wbia
        >>> ibs = wbia.opendb('PZ_MTEST')
        >>> qreq_ = wbia.main_helpers.testdata_qreq_(t=['default:fg_on=False'])
        >>> cm_list = qreq_.execute()
        >>> cm = cm_list[0]
        >>> ibs = qreq_.ibs
        >>> aid1 = cm.qaid
        >>> aid2 = cm.get_top_aids()[0]
        >>> aid_list = None
        >>> options = get_aidpair_context_menu_options(ibs, aid1, aid2, cm, qreq_, aid_list)
        >>> result = ('options = %s' % (ut.repr2(options),))
        >>> print(result)
    """
    if ut.VERBOSE:
        logger.info('[inspect_gui] Building AID pair context menu options')
    options = []

    # assert qreq_ is not None, 'must specify qreq_'

    if cm is not None:
        # MAKE SURE THIS IS ALL CM
        show_chip_match_features_option = (
            'Show chip feature matches',
            partial(cm.ishow_single_annotmatch, qreq_, aid2, mode=0),
        )
        if aid_list is not None:
            # Give a subcontext menu for multiple options
            def partial_show_chip_matches_to(aid_):
                return lambda: cm.ishow_single_annotmatch(qreq_, aid_, mode=0)

            show_chip_match_features_option = (
                'Show chip feature matches',
                [('to aid=%r' % (aid_, ), partial_show_chip_matches_to(aid_))
                 for aid_ in aid_list],
            )

        def show_single_namematch():
            import wbia.plottool as pt

            ax = cm.show_single_namematch(qreq_, aid2, mode=0)
            ax = pt.gca()
            ax.figure.canvas.draw()
            pt.update()

        options += [
            show_chip_match_features_option,
            ('Show name feature matches', show_single_namematch),
        ]

    with_interact_chips = True

    if with_interact_chips:
        chip_contex_options = make_annotpair_context_options(
            ibs, aid1, aid2, qreq_)
        if len(chip_contex_options) > 2:
            options += [
                ('Annot Conte&xt Options', chip_contex_options),
            ]
        else:
            options += chip_contex_options

    with_review_options = True

    from wbia.viz import viz_graph2

    if with_review_options:
        aid_list2 = [aid1, aid2]
        options += [
            ('Mark as &Reviewed',
             lambda: ibs.set_annot_pair_as_reviewed(aid1, aid2)),
            (
                'Mark as &True Match.',
                lambda: set_annot_pair_as_positive_match_(
                    ibs, aid1, aid2, cm, qreq_, **kwargs),
            ),
            (
                'Mark as &False Match.',
                lambda: set_annot_pair_as_negative_match_(
                    ibs, aid1, aid2, cm, qreq_, **kwargs),
            ),
            # ('Mark Disjoint Viewpoints.',
            # lambda:  set_annot_pair_as_unknown_match_(
            #     ibs, aid1, aid2, cm, qreq_, **kwargs)),
            (
                'Inspect Match Candidates',
                lambda: review_match(
                    ibs, aid1, aid2, qreq_=qreq_, cm=cm, **kwargs),
            ),
            # FIXME, more than 2 aids
            (
                'New Graph Interaction (Names)',
                partial(
                    viz_graph2.make_qt_graph_interface,
                    ibs,
                    nids=ibs.get_annot_nids(aid_list2),
                ),
            ),
        ]

    with_vsone = True
    if with_vsone:
        options += [(
            'Tune Vsone(vt)',
            make_vsone_context_options(ibs, aid1, aid2, qreq_=qreq_)[0][1],
        )]

    with_vsmany = True
    if with_vsmany:

        def vsmany_load_and_show():
            if qreq_ is None:
                logger.info('no qreq_ given')
                return None
                # qreq2_ = ibs.new_query_request([qaid], [daid], cfgdict={})
            else:
                qreq2_ = qreq_
            cm = qreq2_.execute([aid1])[0]
            cm.ishow_single_annotmatch(qreq_, aid2, mode=0)

        options += [
            ('Load Vsmany', vsmany_load_and_show),
        ]
        pass

    with_match_tags = True
    if with_match_tags:
        pair_tag_options = make_aidpair_tag_context_options(ibs, aid1, aid2)
        options += [('Match Ta&gs', pair_tag_options)]

    if ut.is_developer():

        def dev_debug():
            logger.info('=== DBG ===')
            logger.info('ibs = %r' % (ibs, ))
            logger.info('cm = %r' % (cm, ))
            logger.info('aid1 = %r' % (aid1, ))
            logger.info('aid2 = %r' % (aid2, ))
            logger.info('qreq_ = %r' % (qreq_, ))
            cm.print_inspect_str(qreq_)
            cm.print_rawinfostr()

            cm2 = cm.extend_results(qreq_)
            cm2.print_inspect_str(qreq_)
            cm2.print_rawinfostr()

        def dev_embed(ibs=ibs, aid1=aid1, aid2=aid2, cm=cm, qreq_=qreq_):
            ut.embed()

        options += [
            ('dev pair context embed', dev_embed),
            ('dev pair context debug', dev_debug),
        ]
    return options
Exemplo n.º 32
0
def test_vsone_errors(ibs, daids, qaid2_qres_vsmany, qaid2_qres_vsone,
                      incinfo):
    """
    ibs1 = ibs_gt
    ibs2 = ibs (the current test database, sorry for the backwardness)
    aid1_to_aid2 - maps annots from ibs1 to ibs2
    """
    WASH = 'wash'
    BOTH_FAIL = 'both_fail'
    SINGLETON = 'singleton'
    VSMANY_OUTPERFORMED = 'vsmany_outperformed'
    VSMANY_DOMINATES = 'vsmany_dominates'
    VSMANY_WINS = 'vsmany_wins'
    VSONE_WINS = 'vsone_wins'
    if 'testcases' not in incinfo:
        testcases = {}
        for case in [
                WASH, BOTH_FAIL, SINGLETON, VSMANY_OUTPERFORMED,
                VSMANY_DOMINATES, VSMANY_WINS, VSONE_WINS
        ]:
            testcases[case] = []
        incinfo['testcases'] = testcases
    testcases = incinfo['testcases']

    def append_case(case, testtup):
        print('APPENDED NEW TESTCASE: case=%r' % (case, ))
        print('* testup = %r' % (testtup, ))
        print('* vuuid = %r' %
              (ibs_gt.get_annot_visual_uuids(testtup.qaid_t), ))
        if ut.get_argflag('--interupt-case') and case in [
                VSMANY_WINS, VSMANY_DOMINATES
        ]:
            incinfo['interactive'] = True
            incinfo['use_oracle'] = False
            incinfo['STOP'] = True
            if ut.is_developer():
                import plottool as pt  # NOQA
                IPYTHON_COMMANDS = """
                >>> %pylab qt4
                >>> from ibeis.viz.interact import interact_matches  # NOQA
                >>> #qres_vsmany = ut.search_stack_for_localvar('qres_vsmany')
                >>> ibs        = ut.search_stack_for_localvar('ibs')
                >>> daids      = ut.search_stack_for_localvar('daids')
                >>> qnid_t     = ut.search_stack_for_localvar('qnid_t')
                >>> qres_vsone = ut.search_stack_for_localvar('qres_vsone')
                >>> all_nids_t = ut.search_stack_for_localvar('all_nids_t')
                >>> # Find index in daids of correct matches
                >>> cm = qres_vsone
                >>> correct_indices = np.where(np.array(all_nids_t) == qnid_t)[0]
                >>> correct_aids2 = ut.take(daids, correct_indices)
                >>> qaid = cm.qaid
                >>> aid = correct_aids2[0]
                >>> # Report visual uuid for inclusion or exclusion in script
                >>> print(ibs.get_annot_visual_uuids([qaid, aid]))

                >>> # Feature match things
                >>> print('cm.filtkey_list = %r' % (cm.filtkey_list,))
                >>> fm  = cm.aid2_fm[aid]
                >>> fs  = cm.aid2_fs[aid]
                >>> fsv = cm.aid2_fsv[aid]
                >>> mx = 2
                >>> qfx, dfx = fm[mx]
                >>> fsv_single = fsv[mx]
                >>> fs_single = fs[mx]
                >>> # check featweights
                >>> data_featweights = ibs.get_annot_fgweights([aid])[0]
                >>> data_featweights[dfx]
                >>> fnum = pt.next_fnum()
                >>> bad_aid = cm.get_top_aids()[0]
                >>> #match_interaction_good = interact_matches.MatchInteraction(ibs, cm, aid, annot_mode=1)
                >>> #match_interaction_bad = interact_matches.MatchInteraction(ibs, cm, bad_aid)
                >>> match_interaction_good = cm.ishow_matches(ibs, aid, annot_mode=1, fnum=1)
                >>> match_interaction_bad = cm.ishow_matches(ibs, bad_aid, annot_mode=1, fnum=2)
                >>> match_interaction = match_interaction_good
                >>> self = match_interaction
                >>> self.select_ith_match(mx)
                >>> #impossible_to_match = len(correct_indices) > 0
                """
                y = """
                >>> from os.path import exists
                >>> import vtool as vt
                >>> import vtool.patch as vtpatch
                >>> import vtool.image as vtimage  # NOQA
                >>> chip_list = ibs.get_annot_chips([aid])
                >>> kpts_list = ibs.get_annot_kpts([aid])
                >>> probchip_fpath_list = ibs.get_probchip_fpath(aid)
                >>> probchip_list = [vt.imread(fpath, grayscale=True) if exists(fpath) else None for fpath in probchip_fpath_list]
                >>> kpts  = kpts_list[0]
                >>> probchip = probchip_list[0]
                >>> kp = kpts[dfx]
                >>> patch  = vt.get_warped_patch(probchip, kp)[0].astype(np.float32) / 255.0
                >>> fnum2 = pt.next_fnum()
                >>> pt.figure(fnum2, pnum=(1, 2, 1), doclf=True, docla=True)
                >>> pt.imshow(probchip)
                >>> pt.draw_kpts2([kp])
                >>> pt.figure(fnum2, pnum=(1, 2, 2))
                >>> pt.imshow(patch * 255)
                >>> pt.update()
                >>> vt.gaussian_average_patch(patch)
                >>> cm.ishow_top(ibs, annot_mode=1)
                """
                y
                ut.set_clipboard(IPYTHON_COMMANDS)
                #ut.spawn_delayed_ipython_paste()
                ut.embed(remove_pyqt_hook=False)
                IPYTHON_COMMANDS
Exemplo n.º 33
0
from __future__ import absolute_import, division, print_function, unicode_literals

try:
    import utool as ut
    import dtool
except ImportError as ex:
    print('[ibeis !!!] ERROR: Unable to load all core utility modules.')
    print('[ibeis !!!] Perhaps try super_setup.py pull')
    raise

ut.noinject(__name__, '[ibeis.__init__]')
if ut.VERBOSE:
    print('[ibeis] importing ibeis __init__')


if ut.is_developer():
    standard_visualization_functions = [
        'show_image',
        'show_chip',
        'show_chipmatch',
        'show_chipmatches',
        'show_vocabulary',
        #'show_vocabulary',
    ]

# If we dont initialize plottool before <something>
# then it causes a crash in windows. Its so freaking weird.
# something is not guitool, ibeis.viz
# has to be before control, can be after constants, params, and main_module
#import plottool
Exemplo n.º 34
0
    def on_click(self, event):
        aid       = self.daid
        qaid      = self.qaid
        ibs       = self.ibs
        xywh2_ptr = self.xywh2_ptr
        print('[inter] clicked matches')
        if event is None:
            return
        button = event.button
        is_right_click = button == 3

        # Out of axes click
        (x, y, ax) = (event.xdata, event.ydata, event.inaxes)
        if None in [x, y, ax]:
            in_axis = False
            if not is_right_click:
                print('... out of axis')
                self.chipmatch_view()
                viz.draw()
                return
        else:
            in_axis = True

        if in_axis:
            viztype = vh.get_ibsdat(ax, 'viztype', '')
            is_match_type = viztype in ['matches', 'multi_match']
            print('[ir] viztype=%r ' % viztype)
        else:
            is_match_type = False
            viztype = ''

        if is_right_click:
            from ibeis.gui import inspect_gui
            options = []

            if is_match_type:
                options += inspect_gui.get_aidpair_context_menu_options(
                    self.ibs, self.qaid, self.daid, self.cm,
                    qreq_=self.qreq_,
                    #update_callback=self.show_page,
                    #backend_callback=None, aid_list=aid_list)
                )

            options += [
                ('Toggle same_fig', self.toggle_samefig),
                ('Toggle vert', self.toggle_vert),
                ('query last feature', self.query_last_feature),
                ('show each chip', self.show_each_chip),
                ('show each distinctiveness chip', self.show_each_dstncvs_chip),
                ('show each foreground weight chip', self.show_each_fgweight_chip),
                ('show each probchip', self.show_each_probchip),
                ('show coverage', self.show_coverage),
                #('show each probchip', self.query_last_feature),
            ]

            #options.append(('name_interaction', self.name_interaction))
            if self.H1 is not None:
                options.append(('Toggle homog', self.toggle_homog))
            if ut.is_developer():
                options.append(('dev_reload', self.dev_reload))
                options.append(('dev_embed', self.dev_embed))
            #options.append(('cancel', lambda: print('cancel')))
            self.show_popup_menu(options, event)
            return

        if in_axis:
            key = '' if event.key is None else event.key
            print('key=%r ' % key)
            ctrl_down = key.find('control') == 0
            # Click in match axes
            if is_match_type and ctrl_down:
                # Ctrl-Click
                print('.. control click')
                return self.sv_view()
            elif is_match_type:
                if len(self.fm) == 0:
                    print('[inter] no feature matches to click')
                else:
                    # Normal Click
                    # Select nearest feature match to the click
                    kpts1 = ibs.get_annot_kpts([qaid], config2_=self.query_config2_)[0]
                    kpts2 = ibs.get_annot_kpts([aid], config2_=self.data_config2_)[0]
                    kpts1_m = kpts1[self.fm.T[0]]
                    kpts2_m = kpts2[self.fm.T[1]]
                    x2, y2, w2, h2 = xywh2_ptr[0]
                    _mx1, _dist1 = ut.nearest_point(x, y, kpts1_m)
                    _mx2, _dist2 = ut.nearest_point(x - x2, y - y2, kpts2_m)
                    mx = _mx1 if _dist1 < _dist2 else _mx2
                    (fx1, fx2) = self.fm[mx]
                    print('... clicked mx=%r' % mx)
                    print('... fx1, fx2 = %r, %r' % (fx1, fx2,))
                    self.select_ith_match(mx)
            elif viztype in ['warped', 'unwarped']:
                print('clicked at patch')
                ut.print_dict(ph.get_plotdat_dict(ax))
                hs_aid = vh.get_ibsdat(ax, 'aid', None)
                hs_fx = vh.get_ibsdat(ax, 'fx', None)
                #hs_aid = ax.__dict__.get('_hs_aid', None)
                #hs_fx = ax.__dict__.get('_hs_fx', None)
                print('hs_fx = %r' % (hs_fx,))
                print('hs_aid = %r' % (hs_aid,))
                if hs_aid is not None and viztype == 'unwarped':
                    ishow_chip(ibs, hs_aid, fx=hs_fx, fnum=df2.next_fnum())
                elif hs_aid is not None and viztype == 'warped':
                    viz.show_keypoint_gradient_orientations(ibs, hs_aid, hs_fx,
                                                            fnum=df2.next_fnum())
            elif viztype.startswith('colorbar'):
                # Hack to get a specific scoring feature
                sortx = self.fs.argsort()
                idx = np.clip(int(np.round(y * len(sortx))), 0, len(sortx) - 1)
                mx = sortx[idx]
                (fx1, fx2) = self.fm[mx]
                (fx1, fx2) = self.fm[mx]
                print('... selected score at rank idx=%r' % (idx,))
                print('... selected score with fs=%r' % (self.fs[mx],))
                print('... resolved to mx=%r' % mx)
                print('... fx1, fx2 = %r, %r' % (fx1, fx2,))
                self.select_ith_match(mx)
            else:
                print('...Unknown viztype: %r' % viztype)
            viz.draw()
Exemplo n.º 35
0
except ImportError:
    __version__ = '0.0.0'

try:
    import utool as ut
    from wbia import dtool
except ImportError as ex:
    print('[wbia !!!] ERROR: Unable to load all core utility modules.')
    print('[wbia !!!] Perhaps try super_setup.py pull')
    raise

ut.noinject(__name__, '[wbia.__init__]')
if ut.VERBOSE:
    print('[wbia] importing wbia __init__')

if ut.is_developer():
    standard_visualization_functions = [
        'show_image',
        'show_chip',
        'show_chipmatch',
        'show_chipmatches',
        'show_vocabulary',
        #'show_vocabulary',
    ]

# If we dont initialize plottool before <something>
# then it causes a crash in windows. Its so freaking weird.
# something is not guitool, wbia.viz
# has to be before control, can be after constants, params, and entry_points
# import wbia.plottool
Exemplo n.º 36
0
    def plot_chip(self, aid, nRows, nCols, px, fulldraw=True, **kwargs):
        """ Plots an individual chip in a subaxis """
        ibs = self.ibs
        if aid in [self.aid1, self.aid2]:
            # Bold color for the matching chips
            lw = 5
            text_color = np.array((135, 206, 235, 255)) / 255.0
        else:
            lw = 2
            text_color = None

        pnum = (nRows, nCols, px)
        if not fulldraw:
            # not doing full draw so we have to clear any axes
            # that are here already manually
            ax = self.fig.add_subplot(*pnum)
            self.clear_parent_axes(ax)
            #ut.embed()
            #print(subax)

        viz_chip_kw = {
            'fnum': self.fnum,
            'pnum': pnum,
            'nokpts': True,
            'show_name': True,
            'show_gname': False,
            'show_aidstr': True,
            'notitle': True,
            'show_num_gt': False,
            'text_color': text_color,
        }
        if False and ut.is_developer():
            enable_chip_title_prefix = True
            viz_chip_kw.update(
                {
                    'enable_chip_title_prefix': enable_chip_title_prefix,
                    'show_name': True,
                    'show_aidstr': True,
                    'show_yawtext': True,
                    'show_num_gt': True,
                    'show_quality_text': True,
                }
            )

        viz_chip.show_chip(ibs, aid, **viz_chip_kw)
        ax = pt.gca()
        pt.draw_border(ax, color=kwargs.get('color'), lw=lw)
        if kwargs.get('make_buttons', True):
            #divider = pt.ensure_divider(ax)
            butkw = {
                #'divider': divider,
                'ax': ax,
                'size': '13%'
                #'size': '15%'
            }
        # Chip matching/naming options
        nid = ibs.get_annot_name_rowids(aid)
        annotation_unknown = ibs.is_nid_unknown([nid])[0]
        if not annotation_unknown:
            # remove name
            callback = functools.partial(self.unname_annotation, aid)
            self.append_button('remove name (' + ibs.get_name_texts(nid) + ')', callback=callback, **butkw)
        else:
            # new name
            callback = functools.partial(self.mark_annotation_as_new_name, aid)
            self.append_button('mark as new name', callback=callback, **butkw)
        if nid != self.nid2 and not ibs.is_nid_unknown([self.nid2])[0] and not self.is_split_case:
            # match to nid2
            callback = functools.partial(self.rename_annotation, aid, self.nid2)
            text = 'match to name2: ' + ibs.get_name_texts(self.nid2)
            self.append_button(text, callback=callback, **butkw)
        if nid != self.nid1 and not ibs.is_nid_unknown([self.nid1])[0]:
            # match to nid1
            callback = functools.partial(self.rename_annotation, aid, self.nid1)
            text = 'match to name1: ' + ibs.get_name_texts(self.nid1)
            self.append_button(text, callback=callback, **butkw)

        other_nid_list = self.get_other_nids()
        for other_nid in other_nid_list:
            if other_nid == nid:
                continue
            # rename nid2
            callback = functools.partial(self.rename_annotation, aid, other_nid)
            text = 'match to: ' + ibs.get_name_texts(other_nid)
            self.append_button(text, callback=callback, **butkw)
        return ax
Exemplo n.º 37
0
def testdata_expts(
        defaultdb='testdb1',
        default_acfgstr_name_list=['default:qindex=0:10:4,dindex=0:20'],
        default_test_cfg_name_list=['default'],
        a=None,
        t=None,
        p=None,
        qaid_override=None,
        daid_override=None,
        initial_aids=None,
        use_cache=None,
        dbdir=None,
        ibs=None):
    r"""
    Use this if you want data from an experiment.
    Command line interface to quickly get testdata for test_results.

    Command line flags can be used to specify db, aidcfg, pipecfg, qaid
    override, daid override (and maybe initial aids).


    CommandLine:
        python -m ibeis.init.main_helpers testdata_expts

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.other.dbinfo import *  # NOQA
        >>> import ibeis
        >>> ibs, testres = ibeis.testdata_expts(defaultdb='pz_mtest',
        >>>                                     a='timectrl:qsize=2',
        >>>                                     t='invar:ai=[false],ri=false',
        >>>                                     use_cache=false)
        >>> print('testres = %r' % (testres,))
    """
    if ut.VERBOSE:
        print('[main_helpers] testdata_expts')
    import ibeis
    from ibeis.expt import harness
    if a is not None:
        default_acfgstr_name_list = a
    if t is not None and p is None:
        p = t
    if p is not None:
        default_test_cfg_name_list = p

    if isinstance(default_acfgstr_name_list, six.string_types):
        default_acfgstr_name_list = [default_acfgstr_name_list]
    if isinstance(default_test_cfg_name_list, six.string_types):
        default_test_cfg_name_list = [default_test_cfg_name_list]

    #from ibeis.expt import experiment_helpers
    if dbdir is not None:
        dbdir = ut.truepath(dbdir)
    if ibs is None:
        ibs = ibeis.opendb(defaultdb=defaultdb, dbdir=dbdir)
    acfg_name_list = ut.get_argval(('--aidcfg', '--acfg', '-a'),
                                   type_=list,
                                   default=default_acfgstr_name_list)
    test_cfg_name_list = ut.get_argval(('-t', '-p'),
                                       type_=list,
                                       default=default_test_cfg_name_list)
    daid_override = ut.get_argval(('--daid-override', '--daids-override'),
                                  type_=list,
                                  default=daid_override)
    qaid_override = ut.get_argval(
        ('--qaid', '--qaids-override', '--qaid-override'),
        type_=list,
        default=qaid_override)

    # Hack a cache here
    use_bulk_cache = not ut.get_argflag(('--nocache', '--nocache-hs'))
    use_bulk_cache &= ut.is_developer()
    if use_cache is not None:
        use_bulk_cache &= use_cache
    use_bulk_cache &= False
    #use_bulk_cache = True
    if use_bulk_cache:
        from os.path import dirname
        cache_dir = ut.ensuredir(
            (dirname(ut.get_module_dir(ibeis)), 'BULK_TESTRES'))
        _cache_wrp = ut.cached_func('testreslist', cache_dir=cache_dir)
        _load_testres = _cache_wrp(harness.run_expt)
    else:
        _load_testres = harness.run_expt

    testres = _load_testres(ibs,
                            acfg_name_list,
                            test_cfg_name_list,
                            qaid_override=qaid_override,
                            daid_override=daid_override,
                            initial_aids=initial_aids,
                            use_cache=use_cache)
    #testres = test_result.combine_testres_list(ibs, testres_list)

    if ut.VERBOSE:
        print(testres)
    return ibs, testres
Exemplo n.º 38
0
def testdata_expts(defaultdb='testdb1',
                   default_acfgstr_name_list=['default:qindex=0:10:4,dindex=0:20'],
                   default_test_cfg_name_list=['default'],
                   a=None,
                   t=None,
                   p=None,
                   qaid_override=None,
                   daid_override=None,
                   initial_aids=None,
                   use_cache=None):
    """
    Use this if you want data from an experiment.
    Command line interface to quickly get testdata for test_results.

    Command line flags can be used to specify db, aidcfg, pipecfg, qaid
    override, daid override (and maybe initial aids).


    CommandLine:
        python -m ibeis.init.main_helpers testdata_expts

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.other.dbinfo import *  # NOQA
        >>> import ibeis
        >>> ibs, testres = ibeis.testdata_expts(defaultdb='PZ_MTEST', a='timectrl:qsize=2', t='invar:AI=[False],RI=False', use_cache=False)
        >>> print('testres = %r' % (testres,))
    """
    if ut.VERBOSE:
        print('[main_helpers] testdata_expts')
    import ibeis
    from ibeis.expt import harness
    from ibeis.expt import test_result
    if a is not None:
        default_acfgstr_name_list = a
    if t is not None and p is None:
        p = t
    if p is not None:
        default_test_cfg_name_list = p

    if isinstance(default_acfgstr_name_list, six.string_types):
        default_acfgstr_name_list = [default_acfgstr_name_list]
    if isinstance(default_test_cfg_name_list, six.string_types):
        default_test_cfg_name_list = [default_test_cfg_name_list]

    #from ibeis.expt import experiment_helpers
    ibs = ibeis.opendb(defaultdb=defaultdb)
    acfg_name_list = ut.get_argval(('--aidcfg', '--acfg', '-a'), type_=list,
                                   default=default_acfgstr_name_list)
    test_cfg_name_list = ut.get_argval(('-t', '-p'), type_=list, default=default_test_cfg_name_list)
    daid_override = ut.get_argval(('--daid-override', '--daids-override'), type_=list, default=daid_override)
    qaid_override = ut.get_argval(('--qaid', '--qaids-override', '--qaid-override'), type_=list, default=qaid_override)

    # Hack a cache here
    use_bigtest_cache3 = not ut.get_argflag(('--nocache', '--nocache-hs'))
    use_bigtest_cache3 &= ut.is_developer()
    if use_cache is not None:
        use_bigtest_cache3 &= use_cache
    use_bigtest_cache3 &= False
    #use_bigtest_cache3 = True
    if use_bigtest_cache3:
        from os.path import dirname, join
        cache_dir = ut.ensuredir(join(dirname(ut.get_module_dir(ibeis)), 'BIG_TESTLIST_CACHE3'))
        _load_testres = ut.cached_func('testreslist', cache_dir=cache_dir)(harness.run_test_configurations2)
    else:
        _load_testres = harness.run_test_configurations2
    testres_list = _load_testres(
        ibs, acfg_name_list, test_cfg_name_list, qaid_override=qaid_override,
        daid_override=daid_override, initial_aids=initial_aids,
        use_cache=use_cache)
    testres = test_result.combine_testres_list(ibs, testres_list)

    if ut.VERBOSE:
        print(testres)
    return ibs, testres
Exemplo n.º 39
0
    def plot_chip(self, aid, nRows, nCols, px, **kwargs):
        """ Plots an individual chip in a subaxis """
        ibs = self.ibs
        enable_chip_title_prefix = ut.is_developer()
        #enable_chip_title_prefix = False
        if aid in self.comp_aids:
            score    = self.cm.get_annot_scores([aid])[0]
            rawscore = self.cm.get_annot_scores([aid])[0]
            title_suf = kwargs.get('title_suffix', '')
            if score != rawscore:
                if score is None:
                    title_suf += '\n score=____'
                else:
                    title_suf += '\n score=%0.2f' % score
            title_suf += '\n rawscore=%0.2f' % rawscore
        else:
            title_suf = kwargs.get('title_suffix', '')
            if enable_chip_title_prefix:
                title_suf = '\n' + title_suf

        #nid = ibs.get_annot_name_rowids(aid)
        viz_chip_kw = {
            'fnum': self.fnum,
            'pnum': (nRows, nCols, px),
            'nokpts': True,
            'show_gname': False,
            'show_exemplar': False,
            'show_num_gt': False,
            'show_gname': False,
            'title_suffix': title_suf,
            # 'text_color': kwargs.get('color'),
            ###
            #'show_name': False,
            #'show_aidstr': False,
            'enable_chip_title_prefix': enable_chip_title_prefix,
            'show_name': True,
            'show_aidstr': True,
            'show_yawtext': True,
            'show_quality_text': True,
        }

        viz_chip.show_chip(ibs, aid, **viz_chip_kw)
        ax = pt.gca()
        if kwargs.get('make_buttons', True):
            divider = pt.ensure_divider(ax)
            butkw = {
                'divider': divider,
                'size': '13%'
            }

        self.aid2_ax = {}
        self.aid2_border = {}

        if aid in self.comp_aids:
            callback = partial(self.select, aid)
            self.append_button('Select This Animal', callback=callback, **butkw)
            #Hack to toggle colors
            if aid in self.aid_checkbox_states:
                #If we are selecting it, then make it green, otherwise change it back to grey
                if self.aid_checkbox_states[aid]:
                    border = pt.draw_border(ax, color=(0, 1, 0), lw=4)
                else:
                    border = pt.draw_border(ax, color=(.7, .7, .7), lw=4)
                self.aid2_border[aid] = border
            else:
                self.aid_checkbox_states[aid] = False
            self.append_button('Examine', callback=partial(self.examine, aid), **butkw)