示例#1
0
def collect_ibeis_training_annotations(ibs, nDaids_basis, verbose=True):
    # load a dataset
    #dbname = 'PZ_MTEST'
    #dbname = 'GZ_ALL'
    def get_set_groundfalse(ibs, qaids):
        # get groundfalse annots relative to the entire set
        valid_nids = ibs.get_valid_nids()
        qnids = ibs.get_annot_nids(qaids)
        nid_list = list(set(valid_nids) - set(qnids))
        aids_list = ibs.get_name_aids(nid_list)
        return ut.flatten(aids_list)

    # determanism
    np.random.seed(0)
    random.seed(0)
    # TODO: USE ANOT FILTERINGS
    import ibeis
    qaids_all = ibeis.testdata_aids(
        a='default:pername=1,mingt=2,is_known=True')
    qaids = qaids_all[::2]
    print('nQaids = %r' % len(qaids))

    def get_annot_groundtruth_sample(ibs,
                                     aid_list,
                                     per_name=1,
                                     isexemplar=True):
        r"""
        DEPRICATE
        """
        all_trues_list = ibs.get_annot_groundtruth(aid_list,
                                                   noself=True,
                                                   is_exemplar=isexemplar)

        def random_choice(aids):
            size = min(len(aids), per_name)
            return np.random.choice(aids, size, replace=False).tolist()

        sample_trues_list = [
            random_choice(aids) if len(aids) > 0 else []
            for aids in all_trues_list
        ]
        return sample_trues_list

    daids_gt_sample = ut.flatten(
        ibs.get_annot_groundtruth_sample(ibs, qaids, isexemplar=None))
    daids_gf_all = get_set_groundfalse(ibs, qaids)
    ut.assert_eq(len(daids_gt_sample), len(qaids), 'missing gt')
    daids_list = []

    for target_nDaids in ut.ProgressIter(nDaids_basis, lbl='testing dbsize'):
        print('---------------------------')
        # Sample one match from the groundtruth with padding
        daids_gf_sample = ut.random_sample(
            daids_gf_all, max(0, target_nDaids - len(daids_gt_sample)))
        daids = sorted(daids_gt_sample + daids_gf_sample)
        nDaids = len(daids)
        if target_nDaids != nDaids:
            continue
        daids_list.append(daids)
    return qaids, daids_list
示例#2
0
def collect_ibeis_training_annotations(ibs, nDaids_basis, verbose=True):
    # load a dataset
    #dbname = 'PZ_MTEST'
    #dbname = 'GZ_ALL'
    def get_set_groundfalse(ibs, qaids):
        # get groundfalse annots relative to the entire set
        valid_nids = ibs.get_valid_nids()
        qnids = ibs.get_annot_nids(qaids)
        nid_list = list(set(valid_nids) - set(qnids))
        aids_list = ibs.get_name_aids(nid_list)
        return ut.flatten(aids_list)

    # determanism
    np.random.seed(0)
    random.seed(0)
    # TODO: USE ANOT FILTERINGS
    import ibeis
    qaids_all = ibeis.testdata_aids(a='default:pername=1,mingt=2,is_known=True')
    qaids = qaids_all[::2]
    print('nQaids = %r' % len(qaids))

    def get_annot_groundtruth_sample(ibs, aid_list, per_name=1, isexemplar=True):
        r"""
        DEPRICATE
        """
        all_trues_list = ibs.get_annot_groundtruth(aid_list, noself=True, is_exemplar=isexemplar)
        def random_choice(aids):
            size = min(len(aids), per_name)
            return np.random.choice(aids, size, replace=False).tolist()
        sample_trues_list = [random_choice(aids) if len(aids) > 0 else [] for aids in all_trues_list]
        return sample_trues_list

    daids_gt_sample = ut.flatten(ibs.get_annot_groundtruth_sample(ibs, qaids, isexemplar=None))
    daids_gf_all = get_set_groundfalse(ibs, qaids)
    ut.assert_eq(len(daids_gt_sample), len(qaids), 'missing gt')
    daids_list = []

    for target_nDaids in ut.ProgressIter(nDaids_basis, lbl='testing dbsize'):
        print('---------------------------')
        # Sample one match from the groundtruth with padding
        daids_gf_sample = ut.random_sample(daids_gf_all, max(0, target_nDaids - len(daids_gt_sample)))
        daids = sorted(daids_gt_sample + daids_gf_sample)
        nDaids = len(daids)
        if target_nDaids != nDaids:
            continue
        daids_list.append(daids)
    return qaids, daids_list
示例#3
0
文件: testem.py 项目: warunanc/ibeis
 def sampleone(list_):
     return ut.random_sample(list_, 1, rng=rng)[0]
示例#4
0
    def _cm_training_pairs(
        infr,
        qreq_=None,
        cm_list=None,
        top_gt=2,
        mid_gt=2,
        bot_gt=2,
        top_gf=2,
        mid_gf=2,
        bot_gf=2,
        rand_gt=2,
        rand_gf=2,
        rng=None,
    ):
        """
        Constructs training data for a pairwise classifier

        CommandLine:
            python -m wbia.algo.graph.core _cm_training_pairs

        Example:
            >>> # xdoctest: +REQUIRES(--slow)
            >>> # ENABLE_DOCTEST
            >>> from wbia.algo.graph.core import *  # NOQA
            >>> infr = testdata_infr('PZ_MTEST')
            >>> infr.exec_matching(cfgdict={
            >>>     'can_match_samename': True,
            >>>     'K': 4,
            >>>     'Knorm': 1,
            >>>     'prescore_method': 'csum',
            >>>     'score_method': 'csum'
            >>> })
            >>> from wbia.algo.graph.core import *  # NOQA
            >>> exec(ut.execstr_funckw(infr._cm_training_pairs))
            >>> rng = np.random.RandomState(42)
            >>> aid_pairs = np.array(infr._cm_training_pairs(rng=rng))
            >>> print(len(aid_pairs))
            >>> assert np.sum(aid_pairs.T[0] == aid_pairs.T[1]) == 0
        """
        if qreq_ is None:
            cm_list = infr.cm_list
            qreq_ = infr.qreq_
        ibs = infr.ibs
        aid_pairs = []
        dnids = qreq_.get_qreq_annot_nids(qreq_.daids)
        # dnids = qreq_.get_qreq_annot_nids(qreq_.daids)
        rng = ut.ensure_rng(rng)
        for cm in ut.ProgIter(cm_list, lbl='building pairs'):
            all_gt_aids = cm.get_top_gt_aids(ibs)
            all_gf_aids = cm.get_top_gf_aids(ibs)
            gt_aids = ut.take_percentile_parts(all_gt_aids, top_gt, mid_gt, bot_gt)
            gf_aids = ut.take_percentile_parts(all_gf_aids, top_gf, mid_gf, bot_gf)
            # get unscored examples
            unscored_gt_aids = [
                aid for aid in qreq_.daids[cm.qnid == dnids] if aid not in cm.daid2_idx
            ]
            rand_gt_aids = ut.random_sample(unscored_gt_aids, rand_gt, rng=rng)
            # gf_aids = cm.get_groundfalse_daids()
            _gf_aids = qreq_.daids[cm.qnid != dnids]
            _gf_aids = qreq_.daids.compress(cm.qnid != dnids)
            # gf_aids = ibs.get_annot_groundfalse(cm.qaid, daid_list=qreq_.daids)
            rand_gf_aids = ut.random_sample(_gf_aids, rand_gf, rng=rng).tolist()
            chosen_daids = ut.unique(gt_aids + gf_aids + rand_gf_aids + rand_gt_aids)
            aid_pairs.extend([(cm.qaid, aid) for aid in chosen_daids if cm.qaid != aid])

        return aid_pairs
示例#5
0
文件: testem.py 项目: Erotemic/ibeis
 def sampleone(list_):
     return ut.random_sample(list_, 1, rng=rng)[0]