def trytest_incremental_add(ibs): r""" Args: ibs (IBEISController): CommandLine: python -m ibeis.algo.hots._neighbor_experiment --test-test_incremental_add Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.neighbor_index_cache import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb('PZ_MTEST') >>> result = test_incremental_add(ibs) >>> print(result) """ import ibeis sample_aids = ibeis.testdata_aids(a='default:pername=1,mingt=2') aids1 = sample_aids[::2] aids2 = sample_aids[0:5] aids3 = sample_aids[:-1] # NOQA daid_list = aids1 # NOQA qreq_ = ibs.new_query_request(aids1, aids1) nnindexer1 = neighbor_index_cache.request_ibeis_nnindexer( ibs.new_query_request(aids1, aids1)) # NOQA nnindexer2 = neighbor_index_cache.request_ibeis_nnindexer( ibs.new_query_request(aids2, aids2)) # NOQA # TODO: SYSTEM use visual uuids items = ibs.get_annot_visual_uuids(aids3) uuid_map_fpath = neighbor_index_cache.get_nnindexer_uuid_map_fpath(qreq_) candidate_uuids = neighbor_index_cache.read_uuid_map(uuid_map_fpath, 0) candidate_sets = candidate_uuids covertup = ut.greedy_max_inden_setcover(candidate_sets, items) uncovered_items, covered_items_list, accepted_keys = covertup covered_items = ut.flatten(covered_items_list) covered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(covered_items)) uncovered_aids = sorted( ibs.get_annot_aids_from_visual_uuid(uncovered_items)) nnindexer3 = neighbor_index_cache.request_ibeis_nnindexer( ibs.new_query_request(uncovered_aids, uncovered_aids)) # NOQA # TODO: SYSTEM use visual uuids items = ibs.get_annot_visual_uuids(sample_aids) uuid_map_fpath = neighbor_index_cache.get_nnindexer_uuid_map_fpath(qreq_) #contextlib.closing(shelve.open(uuid_map_fpath)) as uuid_map: candidate_uuids = neighbor_index_cache.read_uuid_map(uuid_map_fpath, 0) candidate_sets = candidate_uuids covertup = ut.greedy_max_inden_setcover(candidate_sets, items) uncovered_items, covered_items_list, accepted_keys = covertup covered_items = ut.flatten(covered_items_list) covered_aids = sorted( ibs.get_annot_aids_from_visual_uuid(covered_items)) # NOQA uncovered_aids = sorted( ibs.get_annot_aids_from_visual_uuid(uncovered_items))
def test_incremental_add(ibs): r""" Args: ibs (IBEISController): CommandLine: python -m ibeis.algo.hots._neighbor_experiment --test-test_incremental_add Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.hots.neighbor_index_cache import * # NOQA >>> import ibeis >>> ibs = ibeis.opendb('PZ_MTEST') >>> result = test_incremental_add(ibs) >>> print(result) """ import ibeis sample_aids = ibeis.testdata_aids(a='default:pername=1,mingt=2') aids1 = sample_aids[::2] aids2 = sample_aids[0:5] aids3 = sample_aids[:-1] # NOQA daid_list = aids1 # NOQA qreq_ = ibs.new_query_request(aids1, aids1) nnindexer1 = neighbor_index_cache.request_ibeis_nnindexer(ibs.new_query_request(aids1, aids1)) # NOQA nnindexer2 = neighbor_index_cache.request_ibeis_nnindexer(ibs.new_query_request(aids2, aids2)) # NOQA # TODO: SYSTEM use visual uuids #daids_hashid = qreq_.ibs.get_annot_hashid_visual_uuid(daid_list) # get_internal_data_hashid() items = ibs.get_annot_visual_uuids(aids3) uuid_map_fpath = neighbor_index_cache.get_nnindexer_uuid_map_fpath(qreq_) candidate_uuids = neighbor_index_cache.read_uuid_map(uuid_map_fpath, 0) candidate_sets = candidate_uuids covertup = ut.greedy_max_inden_setcover(candidate_sets, items) uncovered_items, covered_items_list, accepted_keys = covertup covered_items = ut.flatten(covered_items_list) covered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(covered_items)) uncovered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(uncovered_items)) nnindexer3 = neighbor_index_cache.request_ibeis_nnindexer(ibs.new_query_request(uncovered_aids, uncovered_aids)) # NOQA # TODO: SYSTEM use visual uuids #daids_hashid = qreq_.ibs.get_annot_hashid_visual_uuid(daid_list) # get_internal_data_hashid() items = ibs.get_annot_visual_uuids(sample_aids) uuid_map_fpath = neighbor_index_cache.get_nnindexer_uuid_map_fpath(qreq_) #contextlib.closing(shelve.open(uuid_map_fpath)) as uuid_map: candidate_uuids = neighbor_index_cache.read_uuid_map(uuid_map_fpath, 0) candidate_sets = candidate_uuids covertup = ut.greedy_max_inden_setcover(candidate_sets, items) uncovered_items, covered_items_list, accepted_keys = covertup covered_items = ut.flatten(covered_items_list) covered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(covered_items)) # NOQA uncovered_aids = sorted(ibs.get_annot_aids_from_visual_uuid(uncovered_items))
def load_indexer(qreq_, verbose=ut.NOT_QUIET, force=False, prog_hook=None): if not force and qreq_.indexer is not None: if prog_hook is not None: prog_hook.set_progress(1, 1, lbl='Indexer is loaded') return False else: index_method = qreq_.qparams.index_method if prog_hook is not None: prog_hook.set_progress(0, 1, lbl='Loading %s indexer' % (index_method,)) if index_method == 'single': # TODO: SYSTEM updatable indexer if ut.VERYVERBOSE or verbose: print('[qreq] loading single indexer normalizer') indexer = neighbor_index_cache.request_ibeis_nnindexer( qreq_, verbose=verbose, prog_hook=prog_hook, **qreq_._indexer_request_params) #elif index_method == 'multi': # if ut.VERYVERBOSE or verbose: # print('[qreq] loading multi indexer normalizer') # indexer = multi_index.request_ibeis_mindexer( # qreq_, verbose=verbose) else: raise ValueError('unknown index_method=%r' % (index_method,)) #if qreq_.prog_hook is not None: # hook.set_progress(4, 4, lbl='building indexer') qreq_.indexer = indexer return True
def load_indexer(qreq_, verbose=ut.NOT_QUIET, force=False): if not force and qreq_.indexer is not None: return False else: index_method = qreq_.qparams.index_method if index_method == 'single': # TODO: SYSTEM updatable indexer if ut.VERYVERBOSE or verbose: print('[qreq] loading single indexer normalizer') indexer = neighbor_index_cache.request_ibeis_nnindexer( qreq_, verbose=verbose, **qreq_._indexer_request_params) elif index_method == 'multi': if ut.VERYVERBOSE or verbose: print('[qreq] loading multi indexer normalizer') indexer = multi_index.request_ibeis_mindexer( qreq_, verbose=verbose) else: raise AssertionError('uknown index_method=%r' % (index_method,)) qreq_.indexer = indexer return True