In [20]:
from ibeis.all_imports import *
ibs = ibeis.opendb('PZ_Mothers')
print(ibs.get_infostr())
per_name = 1


[main] _init_ibeis()
[ibs._init_dirs] ibs.dbdir = '/media/Store/data/work/PZ_Mothers'
[ibs] successfully loaded config

    workdir = '/media/Store/data/work'
    dbname = 'PZ_Mothers'
    num_images = 118
    num_annotations = 119
    num_names = 42
    

In [21]:
aid_list = ibs.get_valid_aids()

In [22]:
def get_annot_groundfalse_sample(ibs, aid_list, per_name=1):
    nid_list = ibs.get_annot_nids(aid_list)
    nid2_aids = utool.group_items(aid_list, nid_list)

    for nid in six.iterkeys(nid2_aids):
        # Remove unknown
        if ibs.is_nid_unknown(nid):
            del nid2_aids[nid]
        # Cast into numpy arrays
        aids =  np.array(nid2_aids[nid])
        nid2_aids[nid] = aids
        # Shuffle known annotations in each name
        #np.random.shuffle(aids)
    def _sample(nid_):
        aids_iter = (aids for nid, aids in six.iteritems(nid2_aids) if nid != nid_)
        sample_gf_aids = np.hstack([np.random.choice(aids, per_name) for aids in aids_iter])
        return sample_gf_aids.tolist()

    gf_aids_list = [_sample(nid_) for nid_ in nid_list]
    return gf_aids_list

In [23]:
gf_aids_list = get_annot_groundfalse_sample(ibs, aid_list, per_name=1)
strlist = [utool.truncate_str(str(aids), maxlen=80) for aids in gf_aids_list]
print('\n'.join(strlist[::10]))


[5, 9, 10, 16, 18, 22, 27, 30, 35, 37, 41, 42, 44, ~~~TRUNCATED~~~ 11, 114, 116]
[3, 7, 9, 16, 20, 24, 27, 30, 35, 37, 41, 42, 44,  ~~~TRUNCATED~~~ 11, 114, 116]
[1, 8, 9, 12, 16, 22, 27, 33, 35, 38, 39, 42, 44,  ~~~TRUNCATED~~~ 12, 114, 118]
[3, 6, 9, 11, 16, 20, 26, 27, 35, 36, 40, 42, 43,  ~~~TRUNCATED~~~ 09, 114, 118]
[2, 6, 9, 15, 16, 21, 24, 28, 29, 35, 37, 42, 43,  ~~~TRUNCATED~~~ 11, 114, 116]
[2, 6, 9, 12, 16, 21, 26, 28, 30, 35, 38, 40, 42,  ~~~TRUNCATED~~~ 10, 114, 115]
[3, 5, 9, 15, 16, 21, 22, 28, 29, 35, 36, 41, 42,  ~~~TRUNCATED~~~ 09, 114, 118]
[2, 5, 9, 10, 16, 21, 24, 27, 32, 35, 38, 41, 42,  ~~~TRUNCATED~~~ 13, 114, 118]
[3, 7, 9, 15, 16, 20, 24, 28, 34, 35, 36, 40, 42,  ~~~TRUNCATED~~~ 11, 114, 117]
[1, 8, 9, 12, 16, 17, 23, 28, 34, 35, 37, 41, 42,  ~~~TRUNCATED~~~ 09, 114, 118]
[2, 5, 9, 13, 16, 17, 24, 28, 29, 35, 37, 40, 42,  ~~~TRUNCATED~~~ 09, 114, 115]
[2, 5, 9, 14, 16, 19, 26, 27, 32, 35, 36, 39, 42,  ~~~TRUNCATED~~~ 08, 114, 115]

In [24]:
all_trues_list = ibs.get_annot_groundtruth(aid_list, noself=True, is_exemplar=True)

In [30]:
all_trues_list = ibs.get_annot_groundtruth(aid_list, noself=True, is_exemplar=True)
    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]

In [31]:
print(sample_trues_list)


[[2], [4], [1], [2], [7], [8], [6], [7], [], [11], [12], [11], [15], [10], [12], [], [21], [20], [18], [18], [17], [26], [24], [25], [22], [24], [28], [27], [32], [32], [29], [31], [29], [32], [], [37], [36], [36], [40], [39], [40], [], [44], [43], [43], [48], [48], [49], [46], [51], [50], [], [54], [53], [56], [55], [], [59], [58], [58], [], [64], [65], [62], [63], [64], [], [69], [68], [72], [70], [70], [70], [73], [], [78], [80], [79], [78], [77], [82], [83], [82], [], [88], [87], [88], [85], [90], [89], [90], [94], [92], [95], [93], [92], [95], [], [100], [101], [103], [99], [99], [], [107], [105], [105], [], [112], [111], [113], [110], [112], [], [116], [115], [119], [119], [116]]