def check_merge(ibs_src, ibs_dst): aid_list1 = ibs_src.get_valid_aids() gid_list1 = ibs_src.get_annot_gids(aid_list1) gname_list1 = ibs_src.get_image_uris(gid_list1) image_uuid_list1 = ibs_src.get_image_uuids(gid_list1) gid_list2 = ibs_dst.get_image_gids_from_uuid(image_uuid_list1) gname_list2 = ibs_dst.get_image_uris(gid_list2) # Asserts ut.assert_all_not_None(gid_list1, 'gid_list1') ut.assert_all_not_None(gid_list2, 'gid_list2') ut.assert_lists_eq(gname_list1, gname_list2, 'faild gname') # Image UUIDS should be consistent between databases image_uuid_list2 = ibs_dst.get_image_uuids(gid_list2) ut.assert_lists_eq(image_uuid_list1, image_uuid_list2, 'failed uuid') aids_list1 = ibs_src.get_image_aids(gid_list1) aids_list2 = ibs_dst.get_image_aids(gid_list2) avuuids_list1 = ibs_src.unflat_map(ibs_src.get_annot_visual_uuids, aids_list1) avuuids_list2 = ibs_dst.unflat_map(ibs_dst.get_annot_visual_uuids, aids_list2) issubset_list = [ set(avuuids1).issubset(set(avuuids2)) for avuuids1, avuuids2 in zip(avuuids_list1, avuuids_list2) ] assert all(issubset_list ), 'ibs_src must be a subset of ibs_dst: issubset_list=%r' % ( issubset_list, ) # aids_depth1 = ut.depth_profile(aids_list1) # aids_depth2 = ut.depth_profile(aids_list2) # depth might not be true if ibs_dst is not empty # ut.assert_lists_eq(aids_depth1, aids_depth2, 'failed depth') logger.info('Merge seems ok...')
def _assert_self(inva, qreq_): ibs = qreq_.ibs assert len(inva.aids) == len(inva.wx_lists) assert len(inva.aids) == len(inva.fxs_lists) assert len(inva.aids) == len(inva.maws_lists) assert len(inva.aids) == len(inva.agg_rvecs) assert len(inva.aids) == len(inva.agg_flags) nfeat_list1 = ibs.get_annot_num_feats(inva.aids, config2_=qreq_.qparams) nfeat_list2 = [sum(ut.lmap(len, fx_list)) for fx_list in inva.fxs_lists] nfeat_list3 = [sum(ut.lmap(len, maws)) for maws in inva.maws_lists] ut.assert_lists_eq(nfeat_list1, nfeat_list2) ut.assert_lists_eq(nfeat_list1, nfeat_list3)
def make_incremental_test_database(ibs_gt, aid_list1, reset): """ Makes test database. adds image and annotations but does not transfer names. if reset is true the new database is gaurenteed to be built from a fresh start. Args: ibs_gt (IBEISController): aid_list1 (list): reset (bool): if True the test database is completely rebuilt Returns: IBEISController: ibs2 """ import ibeis print('make_incremental_test_database. reset=%r' % (reset, )) aids1_hashid = ut.hashstr_arr(aid_list1) prefix = '_INCTEST_' + aids1_hashid + '_' dbname2 = prefix + ibs_gt.get_dbname() ibs2 = ibeis.opendb(dbname2, allow_newdir=True, delete_ibsdir=reset, use_cache=False) # reset if flag specified or no data in ibs2 if reset or len(ibs2.get_valid_gids()) == 0: assert len(ibs2.get_valid_aids()) == 0 assert len(ibs2.get_valid_gids()) == 0 assert len(ibs2.get_valid_nids()) == 0 # Get annotations and their images from database 1 gid_list1 = ibs_gt.get_annot_gids(aid_list1) gpath_list1 = ibs_gt.get_image_paths(gid_list1) # Add all images from database 1 to database 2 gid_list2 = ibs2.add_images(gpath_list1, auto_localize=False) # Image UUIDS should be consistent between databases image_uuid_list1 = ibs_gt.get_image_uuids(gid_list1) image_uuid_list2 = ibs2.get_image_uuids(gid_list2) assert image_uuid_list1 == image_uuid_list2 ut.assert_lists_eq(image_uuid_list1, image_uuid_list2) return ibs2
def make_incremental_test_database(ibs_gt, aid_list1, reset): """ Makes test database. adds image and annotations but does not transfer names. if reset is true the new database is gaurenteed to be built from a fresh start. Args: ibs_gt (IBEISController): aid_list1 (list): reset (bool): if True the test database is completely rebuilt Returns: IBEISController: ibs2 """ import ibeis print('make_incremental_test_database. reset=%r' % (reset,)) aids1_hashid = ut.hashstr_arr(aid_list1) prefix = '_INCTEST_' + aids1_hashid + '_' dbname2 = prefix + ibs_gt.get_dbname() ibs2 = ibeis.opendb(dbname2, allow_newdir=True, delete_ibsdir=reset, use_cache=False) # reset if flag specified or no data in ibs2 if reset or len(ibs2.get_valid_gids()) == 0: assert len(ibs2.get_valid_aids()) == 0 assert len(ibs2.get_valid_gids()) == 0 assert len(ibs2.get_valid_nids()) == 0 # Get annotations and their images from database 1 gid_list1 = ibs_gt.get_annot_gids(aid_list1) gpath_list1 = ibs_gt.get_image_paths(gid_list1) # Add all images from database 1 to database 2 gid_list2 = ibs2.add_images(gpath_list1, auto_localize=False) # Image UUIDS should be consistent between databases image_uuid_list1 = ibs_gt.get_image_uuids(gid_list1) image_uuid_list2 = ibs2.get_image_uuids(gid_list2) assert image_uuid_list1 == image_uuid_list2 ut.assert_lists_eq(image_uuid_list1, image_uuid_list2) return ibs2
def assert_testdb_annot_consistency(ibs_gt, ibs2, aid_list1, aid_list2): """ just tests uuids if anything goes wrong this should fix it: from ibeis.other import ibsfuncs aid_list1 = ibs_gt.get_valid_aids() ibs_gt.update_annot_visual_uuids(aid_list1) ibs2.update_annot_visual_uuids(aid_list2) ibsfuncs.fix_remove_visual_dupliate_annotations(ibs_gt) """ assert len(aid_list2) == len(aid_list1) visualtup1 = ibs_gt.get_annot_visual_uuid_info(aid_list1) visualtup2 = ibs2.get_annot_visual_uuid_info(aid_list2) _visual_uuid_list1 = [ut.augment_uuid(*tup) for tup in zip(*visualtup1)] _visual_uuid_list2 = [ut.augment_uuid(*tup) for tup in zip(*visualtup2)] assert ut.hashstr(visualtup1) == ut.hashstr(visualtup2) ut.assert_lists_eq(visualtup1[0], visualtup2[0]) ut.assert_lists_eq(visualtup1[1], visualtup2[1]) ut.assert_lists_eq(visualtup1[2], visualtup2[2]) #semantic_uuid_list1 = ibs_gt.get_annot_semantic_uuids(aid_list1) #semantic_uuid_list2 = ibs2.get_annot_semantic_uuids(aid_list2) visual_uuid_list1 = ibs_gt.get_annot_visual_uuids(aid_list1) visual_uuid_list2 = ibs2.get_annot_visual_uuids(aid_list2) # make sure visual uuids are still determenistic ut.assert_lists_eq(visual_uuid_list1, visual_uuid_list2) ut.assert_lists_eq(_visual_uuid_list1, visual_uuid_list1) ut.assert_lists_eq(_visual_uuid_list2, visual_uuid_list2) if ut.VERBOSE: ibs1_dup_annots = ut.debug_duplicate_items(visual_uuid_list1) ibs2_dup_annots = ut.debug_duplicate_items(visual_uuid_list2) else: ibs1_dup_annots = ut.find_duplicate_items(visual_uuid_list1) ibs2_dup_annots = ut.find_duplicate_items(visual_uuid_list2) # if these fail try ibsfuncs.fix_remove_visual_dupliate_annotations assert len(ibs1_dup_annots) == 0 assert len(ibs2_dup_annots) == 0
def query_chips(ibs, qaid_list=None, daid_list=None, cfgdict=None, use_cache=None, use_bigcache=None, qreq_=None, return_request=False, verbose=pipeline.VERB_PIPELINE, save_qcache=None, prog_hook=None, return_cm_dict=False, return_cm_simple_dict=False): r""" Submits a query request to the hotspotter recognition pipeline. Returns a list of QueryResult objects. Args: qaid_list (list): a list of annotation ids to be submitted as queries daid_list (list): a list of annotation ids used as the database that will be searched cfgdict (dict): dictionary of configuration options used to create a new QueryRequest if not already specified use_cache (bool): turns on/off chip match cache (default: True) use_bigcache (bool): turns one/off chunked chip match cache (default: True) qreq_ (QueryRequest): optional, a QueryRequest object that overrides all previous settings return_request (bool): returns the request which will be created if one is not already specified verbose (bool): default=False, turns on verbose printing Returns: list: a list of ChipMatch objects containing the matching annotations, scores, and feature matches Returns(2): tuple: (cm_list, qreq_) - a list of query results and optionally the QueryRequest object used RESTful: Method: PUT URL: /api/query/chips/ CommandLine: python -m ibeis.web.apis_query --test-query_chips # Test speed of single query python -m ibeis --tf IBEISController.query_chips --db PZ_Master1 \ -a default:qindex=0:1,dindex=0:500 --nocache-hs python -m ibeis --tf IBEISController.query_chips --db PZ_Master1 \ -a default:qindex=0:1,dindex=0:3000 --nocache-hs python -m ibeis.web.apis_query --test-query_chips:1 --show python -m ibeis.web.apis_query --test-query_chips:2 --show Example: >>> # SLOW_DOCTEST >>> from ibeis.control.IBEISControl import * # NOQA >>> import ibeis >>> qreq_ = ibeis.testdata_qreq_() >>> ibs = qreq_.ibs >>> cm_list = qreq_.execute() >>> cm = cm_list[0] >>> ut.quit_if_noshow() >>> cm.ishow_analysis(qreq_) >>> ut.show_if_requested() Example: >>> # SLOW_DOCTEST >>> #from ibeis.all_imports import * # NOQA >>> import ibeis >>> from ibeis.control.IBEISControl import * # NOQA >>> qaid_list = [1] >>> daid_list = [1, 2, 3, 4, 5] >>> ibs = ibeis.test_main(db='testdb1') >>> qreq_ = ibs.new_query_request(qaid_list, daid_list) >>> cm = ibs.query_chips(qaid_list, daid_list, use_cache=False, qreq_=qreq_)[0] >>> ut.quit_if_noshow() >>> cm.ishow_analysis(qreq_) >>> ut.show_if_requested() Example1: >>> # SLOW_DOCTEST >>> #from ibeis.all_imports import * # NOQA >>> import ibeis >>> from ibeis.control.IBEISControl import * # NOQA >>> qaid_list = [1] >>> daid_list = [1, 2, 3, 4, 5] >>> ibs = ibeis.test_main(db='testdb1') >>> cfgdict = {'pipeline_root':'BC_DTW'} >>> qreq_ = ibs.new_query_request(qaid_list, daid_list, cfgdict=cfgdict, verbose=True) >>> cm = ibs.query_chips(qaid_list, daid_list, use_cache=False, qreq_=qreq_)[0] >>> ut.quit_if_noshow() >>> cm.ishow_analysis(qreq_) >>> ut.show_if_requested() """ from ibeis.algo.hots import match_chips4 as mc4 # The qaid and daid objects are allowed to be None if qreq_ is # specified if qaid_list is None: qaid_list = qreq_.qaids if daid_list is None: if qreq_ is not None: daid_list = qreq_.daids else: daid_list = ibs.get_valid_aids() qaid_list, was_scalar = ut.wrap_iterable(qaid_list) # Check fo empty queries try: assert len(daid_list) > 0, 'there are no database chips' assert len(qaid_list) > 0, 'there are no query chips' except AssertionError as ex: ut.printex(ex, 'Impossible query request', iswarning=True, keys=['qaid_list', 'daid_list']) if ut.SUPER_STRICT: raise cm_list = [None for qaid in qaid_list] else: # Check for consistency if qreq_ is not None: ut.assert_lists_eq(qreq_.qaids, qaid_list, 'qaids do not agree with qreq_', verbose=True) ut.assert_lists_eq(qreq_.daids, daid_list, 'daids do not agree with qreq_', verbose=True) if qreq_ is None: qreq_ = ibs.new_query_request(qaid_list, daid_list, cfgdict=cfgdict, verbose=verbose) if isinstance(qreq_, dtool.BaseRequest): # Dtool has a new-ish way of doing requests. Eventually requests # will be depricated and all of this will go away though. cm_list = qreq_.execute() else: # Send query to hotspotter (runs the query) cm_list = mc4.submit_query_request(ibs, qaid_list, daid_list, use_cache, use_bigcache, cfgdict=cfgdict, qreq_=qreq_, verbose=verbose, save_qcache=save_qcache, prog_hook=prog_hook) assert isinstance(cm_list, list), 'Chip matches were not returned as a list' if return_cm_dict or return_cm_simple_dict: # Convert to cm_list if return_cm_simple_dict: for cm in cm_list: cm.qauuid = ibs.get_annot_uuids(cm.qaid) cm.dauuid_list = ibs.get_annot_uuids(cm.daid_list) keys = ['qauuid', 'dauuid_list'] cm_list = [cm.as_simple_dict(keys) for cm in cm_list] elif return_cm_dict: cm_list = [cm.as_dict() for cm in cm_list] if was_scalar: # hack for scalar input assert len(cm_list) == 1 cm_list = cm_list[0] if return_request: return cm_list, qreq_ else: return cm_list
def query_chips(ibs, qaid_list=None, daid_list=None, cfgdict=None, use_cache=None, use_bigcache=None, qreq_=None, return_request=False, verbose=pipeline.VERB_PIPELINE, save_qcache=None, prog_hook=None, return_cm_dict=False, return_cm_simple_dict=False): r""" Submits a query request to the hotspotter recognition pipeline. Returns a list of QueryResult objects. Args: qaid_list (list): a list of annotation ids to be submitted as queries daid_list (list): a list of annotation ids used as the database that will be searched cfgdict (dict): dictionary of configuration options used to create a new QueryRequest if not already specified use_cache (bool): turns on/off chip match cache (default: True) use_bigcache (bool): turns one/off chunked chip match cache (default: True) qreq_ (QueryRequest): optional, a QueryRequest object that overrides all previous settings return_request (bool): returns the request which will be created if one is not already specified verbose (bool): default=False, turns on verbose printing Returns: list: a list of ChipMatch objects containing the matching annotations, scores, and feature matches Returns(2): tuple: (cm_list, qreq_) - a list of query results and optionally the QueryRequest object used RESTful: Method: PUT URL: /api/query/chips/ CommandLine: python -m ibeis.web.apis_query --test-query_chips # Test speed of single query python -m ibeis --tf IBEISController.query_chips --db PZ_Master1 \ -a default:qindex=0:1,dindex=0:500 --nocache-hs python -m ibeis --tf IBEISController.query_chips --db PZ_Master1 \ -a default:qindex=0:1,dindex=0:3000 --nocache-hs python -m ibeis.web.apis_query --test-query_chips:1 --show python -m ibeis.web.apis_query --test-query_chips:2 --show Example: >>> # SLOW_DOCTEST >>> from ibeis.control.IBEISControl import * # NOQA >>> import ibeis >>> qreq_ = ibeis.testdata_qreq_() >>> ibs = qreq_.ibs >>> cm_list = qreq_.execute() >>> cm = cm_list[0] >>> ut.quit_if_noshow() >>> cm.ishow_analysis(qreq_) >>> ut.show_if_requested() Example: >>> # SLOW_DOCTEST >>> #from ibeis.all_imports import * # NOQA >>> import ibeis >>> from ibeis.control.IBEISControl import * # NOQA >>> qaid_list = [1] >>> daid_list = [1, 2, 3, 4, 5] >>> ibs = ibeis.test_main(db='testdb1') >>> qreq_ = ibs.new_query_request(qaid_list, daid_list) >>> cm = ibs.query_chips(qaid_list, daid_list, use_cache=False, qreq_=qreq_)[0] >>> ut.quit_if_noshow() >>> cm.ishow_analysis(qreq_) >>> ut.show_if_requested() Example1: >>> # SLOW_DOCTEST >>> #from ibeis.all_imports import * # NOQA >>> import ibeis >>> from ibeis.control.IBEISControl import * # NOQA >>> qaid_list = [1] >>> daid_list = [1, 2, 3, 4, 5] >>> ibs = ibeis.test_main(db='testdb1') >>> cfgdict = {'pipeline_root':'BC_DTW'} >>> qreq_ = ibs.new_query_request(qaid_list, daid_list, cfgdict=cfgdict, verbose=True) >>> cm = ibs.query_chips(qaid_list, daid_list, use_cache=False, qreq_=qreq_)[0] >>> ut.quit_if_noshow() >>> cm.ishow_analysis(qreq_) >>> ut.show_if_requested() """ from ibeis.algo.hots import match_chips4 as mc4 # The qaid and daid objects are allowed to be None if qreq_ is # specified if qaid_list is None: qaid_list = qreq_.qaids if daid_list is None: if qreq_ is not None: daid_list = qreq_.daids else: daid_list = ibs.get_valid_aids() qaid_list, was_scalar = ut.wrap_iterable(qaid_list) # Check fo empty queries try: assert len(daid_list) > 0, 'there are no database chips' assert len(qaid_list) > 0, 'there are no query chips' except AssertionError as ex: ut.printex(ex, 'Impossible query request', iswarning=True, keys=['qaid_list', 'daid_list']) if ut.SUPER_STRICT: raise cm_list = [None for qaid in qaid_list] else: # Check for consistency if qreq_ is not None: ut.assert_lists_eq(qreq_.qaids, qaid_list, 'qaids do not agree with qreq_', verbose=True) ut.assert_lists_eq(qreq_.daids, daid_list, 'daids do not agree with qreq_', verbose=True) if qreq_ is None: qreq_ = ibs.new_query_request(qaid_list, daid_list, cfgdict=cfgdict, verbose=verbose) if isinstance(qreq_, dtool.BaseRequest): # Dtool has a new-ish way of doing requests. Eventually requests # will be depricated and all of this will go away though. cm_list = qreq_.execute() else: # Send query to hotspotter (runs the query) cm_list = mc4.submit_query_request( ibs, qaid_list, daid_list, use_cache, use_bigcache, cfgdict=cfgdict, qreq_=qreq_, verbose=verbose, save_qcache=save_qcache, prog_hook=prog_hook) assert isinstance(cm_list, list), 'Chip matches were not returned as a list' if return_cm_dict or return_cm_simple_dict: # Convert to cm_list if return_cm_simple_dict: for cm in cm_list: cm.qauuid = ibs.get_annot_uuids(cm.qaid) cm.dauuid_list = ibs.get_annot_uuids(cm.daid_list) keys = ['qauuid', 'dauuid_list'] cm_list = [cm.as_simple_dict(keys) for cm in cm_list] elif return_cm_dict: cm_list = [cm.as_dict() for cm in cm_list] if was_scalar: # hack for scalar input assert len(cm_list) == 1 cm_list = cm_list[0] if return_request: return cm_list, qreq_ else: return cm_list
def TEST_IBS_CONTROL(ibs): ibs.delete_all_imagesets() ibs.compute_occurrences() """ get_image_imgsetids / get_imageset_gids """ imgsetid_list = ibs.get_valid_imgsetids() assert imgsetid_list, 'imgsetid_list is empty' gids_list = ibs.get_imageset_gids(imgsetid_list) # print('[TEST] gids_list = %r' % gids_list) assert gids_list, 'gids_list is empty' for gids, imgsetid in zip(gids_list, imgsetid_list): imgsetid_list2 = ibs.get_image_imgsetids(gids) try: assert ([[imgsetid]] * len(imgsetid_list2)) == imgsetid_list2 except AssertionError as ex: utool.printex(ex, key_list=['imgsetid_list2', 'imgsetid']) raise """ set_annot_notes / get_annot_notes """ aid_list = ibs.get_valid_aids() annotation_notes_list = len(aid_list) * ["test text"] assert aid_list, 'aid_list is empty' ibs.set_annot_notes(aid_list, annotation_notes_list) annotation_notes_list2 = ibs.get_annot_notes(aid_list) assert annotation_notes_list2, 'get_annot_notes returned an empty list' #print('[TEST] annotation_notes_list = %r' % annotation_notes_list) #print('[TEST] annotation_notes_list2 = %r' % annotation_notes_list2) assert annotation_notes_list == annotation_notes_list2, 'annotation notes lists do not match' """ set_name_notes / get_name_notes """ nid_list = ibs.get_valid_nids() assert nid_list, 'nid_list is empty' nid_notes_list = len(nid_list) * ['nid notes test'] ibs.set_name_notes(nid_list, nid_notes_list) nid_notes_list2 = ibs.get_name_notes(nid_list) print('[TEST] nid_notes_list = %r' % nid_notes_list) print('[TEST] nid_notes_list2 = %r' % nid_notes_list2) utool.assert_lists_eq(nid_notes_list, nid_notes_list2, 'nid notes lists do not match', verbose=True) assert nid_notes_list == nid_notes_list2, 'nid notes lists do not match' """ set_image_notes / get_image_notes """ gid_list = ibs.get_valid_gids() assert gid_list, 'gid_list is empty' gid_notes_list = len(gid_list) * ['image note test'] ibs.set_image_notes(gid_list, gid_notes_list) gid_notes_list2 = ibs.get_image_notes(gid_list) print('[TEST] gid_notes_list = %r' % gid_notes_list) print('[TEST] gid_notes_list2 = %r' % gid_notes_list2) assert gid_notes_list == gid_notes_list2, 'images notes lists do not match' """ set_annot_bboxes / get_annot_bboxes """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' bbox_list_orig = ibs.get_annot_bboxes(aid_list) bbox_list = [(1, 2, 3, 4)] * len(aid_list) ibs.set_annot_bboxes(aid_list, bbox_list) bbox_list2 = ibs.get_annot_bboxes(aid_list) print('[TEST] aid_list = %r' % (aid_list, )) print('[TEST] bbox_list = %r' % (bbox_list, )) print('[TEST] bbox_list2 = %r' % (bbox_list2, )) assert bbox_list == bbox_list2, 'bbox lists do not match' # put bboxes back to original state # (otherwise other tests will fail on the second run of run_tests.sh) ibs.set_annot_bboxes(aid_list, bbox_list_orig) """ set_annot_verts / get_annot_verts """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' bbox_list_orig = ibs.get_annot_bboxes(aid_list) vert_list_orig = ibs.get_annot_verts(aid_list) vert_list = [((1, 2), (3, 4), (5, 6), (7, 8))] * len(aid_list) print('[TEST] vert_list = %r' % vert_list) assert len(aid_list) == len( vert_list), 'lengths do not match, malformed input' ibs.set_annot_verts(aid_list, vert_list) vert_list2 = ibs.get_annot_verts(aid_list) assert vert_list == vert_list2, 'vert lists do not match' """ set_annot_verts / get_annot_bboxes """ bbox_list = ibs.get_annot_bboxes(aid_list) bbox_list2 = geometry.bboxes_from_vert_list(vert_list2) assert bbox_list == bbox_list2, 'bbox lists do not match' vert_list = [((10, 10), (120, 10), (120, 120), (10, 120))] * len(aid_list) ibs.set_annot_verts(aid_list, vert_list) bbox_list3 = [(10, 10, 110, 110)] * len(aid_list) bbox_list4 = ibs.get_annot_bboxes(aid_list) assert bbox_list3 == bbox_list4, 'bbox lists do not match' # finish this test here """ set_annot_bboxes / get_annot_verts """ bbox_list = [(10, 10, 110, 110)] * len(aid_list) ibs.set_annot_bboxes(aid_list, bbox_list) # test that setting the bounding boxes overrides the vertices vert_list = [((10, 10), (120, 10), (120, 120), (10, 120))] * len(aid_list) vert_list2 = ibs.get_annot_verts(aid_list) assert vert_list == vert_list2, 'vert lists do not match' # put verts back to original state # (otherwise other tests will fail on the second run of run_tests.sh) ibs.set_annot_verts(aid_list, vert_list_orig) assert vert_list_orig == ibs.get_annot_verts( aid_list), 'Verts were not reset to original state' assert bbox_list_orig == ibs.get_annot_bboxes( aid_list), 'Bboxes were not reset to original state' """ set_image_gps / get_image_gps """ gid_list = ibs.get_valid_gids() assert gids, 'gid_list is empty' gps_list_orig = ibs.get_image_gps(gid_list) gps_list = [(x, y) for (x, y) in zip(range(len(gid_list)), range(len(gid_list)))] ibs.set_image_gps(gid_list, gps_list) gps_list2 = ibs.get_image_gps(gid_list) assert gps_list == gps_list2, 'gps lists do not match' ibs.set_image_gps(gid_list, gps_list_orig) assert gps_list_orig == ibs.get_image_gps( gid_list), 'gps was not reset to original state' """ set imageset imagesettext / get imageset imagesettext """ imgsetid_list = ibs.get_valid_imgsetids() enc_text_list_orig = ibs.get_imageset_text(imgsetid_list) enc_text_list = [str(x) for x in range(len(imgsetid_list))] assert imgsetid_list, 'imgsetid_list is empty' print('len imgsetid_list: %d' % len(imgsetid_list)) ibs.set_imageset_text(imgsetid_list, enc_text_list) enc_text_list2 = ibs.get_imageset_text(imgsetid_list) print('enc_text_list = %r' % enc_text_list) print('enc_text_list2 = %r' % enc_text_list2) assert enc_text_list == enc_text_list2, 'imageset text lists do not match' ibs.set_imageset_text(imgsetid_list, enc_text_list_orig) assert enc_text_list_orig == ibs.get_imageset_text( imgsetid_list), 'enc text was not reset' """ set annotation names / get_annot_names """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' orig_names = ibs.get_annot_names(aid_list) new_names = ['TESTNAME_' + str(x) for x in range(len(aid_list))] ibs.set_annot_names(aid_list, new_names) new_names2 = ibs.get_annot_names(aid_list) try: assert new_names == new_names2, 'new_names == new_names2 failed!' except AssertionError as ex: utool.printex(ex, key_list=['new_names', 'new_names2']) raise ibs.set_annot_names(aid_list, orig_names) try: test_names = ibs.get_annot_names(aid_list) assert orig_names == test_names except AssertionError as ex: utool.printex(ex, key_list=['orig_names', 'test_names']) raise """ set annotation species / get annotation species """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' orig_species = ibs.get_annot_species_texts(aid_list) print('orig_species = %r' % (orig_species, )) valid_species = ibs.get_all_species_texts() new_species = [ valid_species[x % len(valid_species)] for x in range(len(aid_list)) ] print('new_species = %r' % (new_species, )) ibs.set_annot_species(aid_list, new_species) try: new_species2 = ibs.get_annot_species_texts(aid_list) assert new_species == new_species2, 'new_species == new_species2 failed!' except AssertionError as ex: utool.printex(ex, key_list=['new_species', 'new_species2']) raise ibs.set_annot_species(aid_list, orig_species) assert orig_species == ibs.get_annot_species_texts( aid_list), 'species were not reset' """ set alr confidence / get alr confidence """ if False: # NOT USING ALR TABLE CURRENTLY aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' alrids_list = ibs.get_annot_alrids(aid_list) assert alrids_list, 'alrids_list is empty' alrid_list = utool.flatten(alrids_list) orig_confidences = ibs.get_alr_confidence(alrid_list) new_confidences = list(range(len(alrid_list))) #ibs.print_alr_table() ibs.set_alr_confidence(alrid_list, new_confidences) #ibs.print_alr_table() new_confidences2 = ibs.get_alr_confidence(alrid_list) assert new_confidences == new_confidences2, 'new_confidences == new_confidences2 failed' ibs.set_alr_confidence(alrid_list, orig_confidences) assert orig_confidences == ibs.get_alr_confidence( alrid_list), 'alr confidences were not reset' """ test metadata """ #ibs.print_tables() #ibs.print_lblannot_table() #ibs.print_alr_table() return locals()
def TEST_IBS_CONTROL(ibs): ibs.delete_all_imagesets() ibs.compute_occurrences() """ get_image_imgsetids / get_imageset_gids """ imgsetid_list = ibs.get_valid_imgsetids() assert imgsetid_list, "imgsetid_list is empty" gids_list = ibs.get_imageset_gids(imgsetid_list) # print('[TEST] gids_list = %r' % gids_list) assert gids_list, "gids_list is empty" for gids, imgsetid in zip(gids_list, imgsetid_list): imgsetid_list2 = ibs.get_image_imgsetids(gids) try: assert ([[imgsetid]] * len(imgsetid_list2)) == imgsetid_list2 except AssertionError as ex: utool.printex(ex, key_list=["imgsetid_list2", "imgsetid"]) raise """ set_annot_notes / get_annot_notes """ aid_list = ibs.get_valid_aids() annotation_notes_list = len(aid_list) * ["test text"] assert aid_list, "aid_list is empty" ibs.set_annot_notes(aid_list, annotation_notes_list) annotation_notes_list2 = ibs.get_annot_notes(aid_list) assert annotation_notes_list2, "get_annot_notes returned an empty list" # print('[TEST] annotation_notes_list = %r' % annotation_notes_list) # print('[TEST] annotation_notes_list2 = %r' % annotation_notes_list2) assert annotation_notes_list == annotation_notes_list2, "annotation notes lists do not match" """ set_name_notes / get_name_notes """ nid_list = ibs.get_valid_nids() assert nid_list, "nid_list is empty" nid_notes_list = len(nid_list) * ["nid notes test"] ibs.set_name_notes(nid_list, nid_notes_list) nid_notes_list2 = ibs.get_name_notes(nid_list) print("[TEST] nid_notes_list = %r" % nid_notes_list) print("[TEST] nid_notes_list2 = %r" % nid_notes_list2) utool.assert_lists_eq(nid_notes_list, nid_notes_list2, "nid notes lists do not match", verbose=True) assert nid_notes_list == nid_notes_list2, "nid notes lists do not match" """ set_image_notes / get_image_notes """ gid_list = ibs.get_valid_gids() assert gid_list, "gid_list is empty" gid_notes_list = len(gid_list) * ["image note test"] ibs.set_image_notes(gid_list, gid_notes_list) gid_notes_list2 = ibs.get_image_notes(gid_list) print("[TEST] gid_notes_list = %r" % gid_notes_list) print("[TEST] gid_notes_list2 = %r" % gid_notes_list2) assert gid_notes_list == gid_notes_list2, "images notes lists do not match" """ set_annot_bboxes / get_annot_bboxes """ aid_list = ibs.get_valid_aids() assert aid_list, "aid_list is empty" bbox_list_orig = ibs.get_annot_bboxes(aid_list) bbox_list = [(1, 2, 3, 4)] * len(aid_list) ibs.set_annot_bboxes(aid_list, bbox_list) bbox_list2 = ibs.get_annot_bboxes(aid_list) print("[TEST] aid_list = %r" % (aid_list,)) print("[TEST] bbox_list = %r" % (bbox_list,)) print("[TEST] bbox_list2 = %r" % (bbox_list2,)) assert bbox_list == bbox_list2, "bbox lists do not match" # put bboxes back to original state # (otherwise other tests will fail on the second run of run_tests.sh) ibs.set_annot_bboxes(aid_list, bbox_list_orig) """ set_annot_verts / get_annot_verts """ aid_list = ibs.get_valid_aids() assert aid_list, "aid_list is empty" bbox_list_orig = ibs.get_annot_bboxes(aid_list) vert_list_orig = ibs.get_annot_verts(aid_list) vert_list = [((1, 2), (3, 4), (5, 6), (7, 8))] * len(aid_list) print("[TEST] vert_list = %r" % vert_list) assert len(aid_list) == len(vert_list), "lengths do not match, malformed input" ibs.set_annot_verts(aid_list, vert_list) vert_list2 = ibs.get_annot_verts(aid_list) assert vert_list == vert_list2, "vert lists do not match" """ set_annot_verts / get_annot_bboxes """ bbox_list = ibs.get_annot_bboxes(aid_list) bbox_list2 = geometry.bboxes_from_vert_list(vert_list2) assert bbox_list == bbox_list2, "bbox lists do not match" vert_list = [((10, 10), (120, 10), (120, 120), (10, 120))] * len(aid_list) ibs.set_annot_verts(aid_list, vert_list) bbox_list3 = [(10, 10, 110, 110)] * len(aid_list) bbox_list4 = ibs.get_annot_bboxes(aid_list) assert bbox_list3 == bbox_list4, "bbox lists do not match" # finish this test here """ set_annot_bboxes / get_annot_verts """ bbox_list = [(10, 10, 110, 110)] * len(aid_list) ibs.set_annot_bboxes(aid_list, bbox_list) # test that setting the bounding boxes overrides the vertices vert_list = [((10, 10), (120, 10), (120, 120), (10, 120))] * len(aid_list) vert_list2 = ibs.get_annot_verts(aid_list) assert vert_list == vert_list2, "vert lists do not match" # put verts back to original state # (otherwise other tests will fail on the second run of run_tests.sh) ibs.set_annot_verts(aid_list, vert_list_orig) assert vert_list_orig == ibs.get_annot_verts(aid_list), "Verts were not reset to original state" assert bbox_list_orig == ibs.get_annot_bboxes(aid_list), "Bboxes were not reset to original state" """ set_image_gps / get_image_gps """ gid_list = ibs.get_valid_gids() assert gids, "gid_list is empty" gps_list_orig = ibs.get_image_gps(gid_list) gps_list = [(x, y) for (x, y) in zip(range(len(gid_list)), range(len(gid_list)))] ibs.set_image_gps(gid_list, gps_list) gps_list2 = ibs.get_image_gps(gid_list) assert gps_list == gps_list2, "gps lists do not match" ibs.set_image_gps(gid_list, gps_list_orig) assert gps_list_orig == ibs.get_image_gps(gid_list), "gps was not reset to original state" """ set imageset imagesettext / get imageset imagesettext """ imgsetid_list = ibs.get_valid_imgsetids() enc_text_list_orig = ibs.get_imageset_text(imgsetid_list) enc_text_list = [str(x) for x in range(len(imgsetid_list))] assert imgsetid_list, "imgsetid_list is empty" print("len imgsetid_list: %d" % len(imgsetid_list)) ibs.set_imageset_text(imgsetid_list, enc_text_list) enc_text_list2 = ibs.get_imageset_text(imgsetid_list) print("enc_text_list = %r" % enc_text_list) print("enc_text_list2 = %r" % enc_text_list2) assert enc_text_list == enc_text_list2, "imageset text lists do not match" ibs.set_imageset_text(imgsetid_list, enc_text_list_orig) assert enc_text_list_orig == ibs.get_imageset_text(imgsetid_list), "enc text was not reset" """ set annotation names / get_annot_names """ aid_list = ibs.get_valid_aids() assert aid_list, "aid_list is empty" orig_names = ibs.get_annot_names(aid_list) new_names = ["TESTNAME_" + str(x) for x in range(len(aid_list))] ibs.set_annot_names(aid_list, new_names) new_names2 = ibs.get_annot_names(aid_list) try: assert new_names == new_names2, "new_names == new_names2 failed!" except AssertionError as ex: utool.printex(ex, key_list=["new_names", "new_names2"]) raise ibs.set_annot_names(aid_list, orig_names) try: test_names = ibs.get_annot_names(aid_list) assert orig_names == test_names except AssertionError as ex: utool.printex(ex, key_list=["orig_names", "test_names"]) raise """ set annotation species / get annotation species """ aid_list = ibs.get_valid_aids() assert aid_list, "aid_list is empty" orig_species = ibs.get_annot_species_texts(aid_list) print("orig_species = %r" % (orig_species,)) valid_species = ibs.get_all_species_texts() new_species = [valid_species[x % len(valid_species)] for x in range(len(aid_list))] print("new_species = %r" % (new_species,)) ibs.set_annot_species(aid_list, new_species) try: new_species2 = ibs.get_annot_species_texts(aid_list) assert new_species == new_species2, "new_species == new_species2 failed!" except AssertionError as ex: utool.printex(ex, key_list=["new_species", "new_species2"]) raise ibs.set_annot_species(aid_list, orig_species) assert orig_species == ibs.get_annot_species_texts(aid_list), "species were not reset" """ set alr confidence / get alr confidence """ if False: # NOT USING ALR TABLE CURRENTLY aid_list = ibs.get_valid_aids() assert aid_list, "aid_list is empty" alrids_list = ibs.get_annot_alrids(aid_list) assert alrids_list, "alrids_list is empty" alrid_list = utool.flatten(alrids_list) orig_confidences = ibs.get_alr_confidence(alrid_list) new_confidences = list(range(len(alrid_list))) # ibs.print_alr_table() ibs.set_alr_confidence(alrid_list, new_confidences) # ibs.print_alr_table() new_confidences2 = ibs.get_alr_confidence(alrid_list) assert new_confidences == new_confidences2, "new_confidences == new_confidences2 failed" ibs.set_alr_confidence(alrid_list, orig_confidences) assert orig_confidences == ibs.get_alr_confidence(alrid_list), "alr confidences were not reset" """ test metadata """ # ibs.print_tables() # ibs.print_lblannot_table() # ibs.print_alr_table() return locals()
def TEST_IBS_CONTROL(ibs): ibs.delete_all_encounters() ibs.compute_encounters() """ get_image_eids / get_encounter_gids """ eid_list = ibs.get_valid_eids() assert eid_list, 'eid_list is empty' gids_list = ibs.get_encounter_gids(eid_list) # print('[TEST] gids_list = %r' % gids_list) assert gids_list, 'gids_list is empty' for gids, eid in zip(gids_list, eid_list): eid_list2 = ibs.get_image_eids(gids) try: assert ([[eid]] * len(eid_list2)) == eid_list2 except AssertionError as ex: utool.printex(ex, key_list=['eid_list2', 'eid']) raise """ set_annot_notes / get_annot_notes """ aid_list = ibs.get_valid_aids() annotation_notes_list = len(aid_list) * ["test text"] assert aid_list, 'aid_list is empty' ibs.set_annot_notes(aid_list, annotation_notes_list) annotation_notes_list2 = ibs.get_annot_notes(aid_list) assert annotation_notes_list2, 'get_annot_notes returned an empty list' #print('[TEST] annotation_notes_list = %r' % annotation_notes_list) #print('[TEST] annotation_notes_list2 = %r' % annotation_notes_list2) assert annotation_notes_list == annotation_notes_list2, 'annotation notes lists do not match' """ set_name_notes / get_name_notes """ nid_list = ibs.get_valid_nids() assert nid_list, 'nid_list is empty' nid_notes_list = len(nid_list) * ['nid notes test'] ibs.set_name_notes(nid_list, nid_notes_list) nid_notes_list2 = ibs.get_name_notes(nid_list) print('[TEST] nid_notes_list = %r' % nid_notes_list) print('[TEST] nid_notes_list2 = %r' % nid_notes_list2) utool.assert_lists_eq(nid_notes_list, nid_notes_list2, 'nid notes lists do not match', verbose=True) assert nid_notes_list == nid_notes_list2, 'nid notes lists do not match' """ set_image_notes / get_image_notes """ gid_list = ibs.get_valid_gids() assert gid_list, 'gid_list is empty' gid_notes_list = len(gid_list) * ['image note test'] ibs.set_image_notes(gid_list, gid_notes_list) gid_notes_list2 = ibs.get_image_notes(gid_list) print('[TEST] gid_notes_list = %r' % gid_notes_list) print('[TEST] gid_notes_list2 = %r' % gid_notes_list2) assert gid_notes_list == gid_notes_list2, 'images notes lists do not match' """ set_annot_bboxes / get_annot_bboxes """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' bbox_list_orig = ibs.get_annot_bboxes(aid_list) bbox_list = [(1, 2, 3, 4)] * len(aid_list) ibs.set_annot_bboxes(aid_list, bbox_list) bbox_list2 = ibs.get_annot_bboxes(aid_list) print('[TEST] aid_list = %r' % (aid_list,)) print('[TEST] bbox_list = %r' % (bbox_list,)) print('[TEST] bbox_list2 = %r' % (bbox_list2,)) assert bbox_list == bbox_list2, 'bbox lists do not match' # put bboxes back to original state # (otherwise other tests will fail on the second run of run_tests.sh) ibs.set_annot_bboxes(aid_list, bbox_list_orig) """ set_annot_verts / get_annot_verts """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' bbox_list_orig = ibs.get_annot_bboxes(aid_list) vert_list_orig = ibs.get_annot_verts(aid_list) vert_list = [((1, 2), (3, 4), (5, 6), (7, 8))] * len(aid_list) print('[TEST] vert_list = %r' % vert_list) assert len(aid_list) == len(vert_list), 'lengths do not match, malformed input' ibs.set_annot_verts(aid_list, vert_list) vert_list2 = ibs.get_annot_verts(aid_list) assert vert_list == vert_list2, 'vert lists do not match' """ set_annot_verts / get_annot_bboxes """ bbox_list = ibs.get_annot_bboxes(aid_list) bbox_list2 = geometry.bboxes_from_vert_list(vert_list2) assert bbox_list == bbox_list2, 'bbox lists do not match' vert_list = [((10, 10), (120, 10), (120, 120), (10, 120))] * len(aid_list) ibs.set_annot_verts(aid_list, vert_list) bbox_list3 = [(10, 10, 110, 110)] * len(aid_list) bbox_list4 = ibs.get_annot_bboxes(aid_list) assert bbox_list3 == bbox_list4, 'bbox lists do not match' # finish this test here """ set_annot_bboxes / get_annot_verts """ bbox_list = [(10, 10, 110, 110)] * len(aid_list) ibs.set_annot_bboxes(aid_list, bbox_list) # test that setting the bounding boxes overrides the vertices vert_list = [((10, 10), (120, 10), (120, 120), (10, 120))] * len(aid_list) vert_list2 = ibs.get_annot_verts(aid_list) assert vert_list == vert_list2, 'vert lists do not match' # put verts back to original state # (otherwise other tests will fail on the second run of run_tests.sh) ibs.set_annot_verts(aid_list, vert_list_orig) assert vert_list_orig == ibs.get_annot_verts(aid_list), 'Verts were not reset to original state' assert bbox_list_orig == ibs.get_annot_bboxes(aid_list), 'Bboxes were not reset to original state' """ set_image_gps / get_image_gps """ gid_list = ibs.get_valid_gids() assert gids, 'gid_list is empty' gps_list_orig = ibs.get_image_gps(gid_list) gps_list = [(x, y) for (x, y) in zip(range(len(gid_list)), range(len(gid_list)))] ibs.set_image_gps(gid_list, gps_list) gps_list2 = ibs.get_image_gps(gid_list) assert gps_list == gps_list2, 'gps lists do not match' ibs.set_image_gps(gid_list, gps_list_orig) assert gps_list_orig == ibs.get_image_gps(gid_list), 'gps was not reset to original state' """ set encounter enctext / get encounter enctext """ eid_list = ibs.get_valid_eids() enc_text_list_orig = ibs.get_encounter_text(eid_list) enc_text_list = [str(x) for x in range(len(eid_list))] assert eid_list, 'eid_list is empty' print('len eid_list: %d' % len(eid_list)) ibs.set_encounter_text(eid_list, enc_text_list) enc_text_list2 = ibs.get_encounter_text(eid_list) print('enc_text_list = %r' % enc_text_list) print('enc_text_list2 = %r' % enc_text_list2) assert enc_text_list == enc_text_list2, 'encounter text lists do not match' ibs.set_encounter_text(eid_list, enc_text_list_orig) assert enc_text_list_orig == ibs.get_encounter_text(eid_list), 'enc text was not reset' """ set annotation names / get_annot_names """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' orig_names = ibs.get_annot_names(aid_list) new_names = ['TESTNAME_' + str(x) for x in range(len(aid_list))] ibs.set_annot_names(aid_list, new_names) new_names2 = ibs.get_annot_names(aid_list) try: assert new_names == new_names2, 'new_names == new_names2 failed!' except AssertionError as ex: utool.printex(ex, key_list=['new_names', 'new_names2']) raise ibs.set_annot_names(aid_list, orig_names) try: test_names = ibs.get_annot_names(aid_list) assert orig_names == test_names except AssertionError as ex: utool.printex(ex, key_list=['orig_names', 'test_names']) raise """ set annotation species / get annotation species """ aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' orig_species = ibs.get_annot_species_texts(aid_list) print('orig_species = %r' % (orig_species,)) valid_species = ibs.get_all_species_texts() new_species = [valid_species[x % len(valid_species)] for x in range(len(aid_list))] print('new_species = %r' % (new_species,)) ibs.set_annot_species(aid_list, new_species) try: new_species2 = ibs.get_annot_species_texts(aid_list) assert new_species == new_species2, 'new_species == new_species2 failed!' except AssertionError as ex: utool.printex(ex, key_list=['new_species', 'new_species2']) raise ibs.set_annot_species(aid_list, orig_species) assert orig_species == ibs.get_annot_species_texts(aid_list), 'species were not reset' """ set alr confidence / get alr confidence """ if False: # NOT USING ALR TABLE CURRENTLY aid_list = ibs.get_valid_aids() assert aid_list, 'aid_list is empty' alrids_list = ibs.get_annot_alrids(aid_list) assert alrids_list, 'alrids_list is empty' alrid_list = utool.flatten(alrids_list) orig_confidences = ibs.get_alr_confidence(alrid_list) new_confidences = list(range(len(alrid_list))) #ibs.print_alr_table() ibs.set_alr_confidence(alrid_list, new_confidences) #ibs.print_alr_table() new_confidences2 = ibs.get_alr_confidence(alrid_list) assert new_confidences == new_confidences2, 'new_confidences == new_confidences2 failed' ibs.set_alr_confidence(alrid_list, orig_confidences) assert orig_confidences == ibs.get_alr_confidence(alrid_list), 'alr confidences were not reset' """ test metadata """ #ibs.print_tables() #ibs.print_lblannot_table() #ibs.print_alr_table() return locals()