def make_annot_semantic_uuid(semantic_infotup): """ Args: semantic_infotup (tuple): (image_uuid_list, verts_list, theta_list, view_list, name_list, species_list) Returns: list: annot_semantic_uuid_list CommandLine: python -m ibeis.algo.preproc.preproc_annot --test-make_annot_semantic_uuid Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.preproc.preproc_annot import * # NOQA >>> ibs, aid_list = testdata_preproc_annot() >>> semantic_infotup = ibs.get_annot_semantic_uuid_info(aid_list) >>> annot_semantic_uuid_list = make_annot_semantic_uuid(semantic_infotup) >>> result = str(annot_semantic_uuid_list[0]) >>> print(result) bf774bf3-582d-dbce-6ca6-329adeb086a6 215ab5f9-fe53-d7d1-59b8-d6b5ce7e6ca6 """ assert len(semantic_infotup) == 6, 'len=%r' % (len(semantic_infotup), ) annot_semantic_uuid_list = [ ut.augment_uuid(*tup) for tup in zip(*semantic_infotup) ] return annot_semantic_uuid_list
def make_annot_semantic_uuid(semantic_infotup): """ Args: semantic_infotup (tuple): (image_uuid_list, verts_list, theta_list, view_list, name_list, species_list) Returns: list: annot_semantic_uuid_list CommandLine: python -m ibeis.algo.preproc.preproc_annot --test-make_annot_semantic_uuid Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.preproc.preproc_annot import * # NOQA >>> ibs, aid_list = testdata_preproc_annot() >>> semantic_infotup = ibs.get_annot_semantic_uuid_info(aid_list) >>> annot_semantic_uuid_list = make_annot_semantic_uuid(semantic_infotup) >>> result = str(annot_semantic_uuid_list[0]) >>> print(result) bf774bf3-582d-dbce-6ca6-329adeb086a6 215ab5f9-fe53-d7d1-59b8-d6b5ce7e6ca6 """ assert len(semantic_infotup) == 6, 'len=%r' % (len(semantic_infotup),) annot_semantic_uuid_list = [ut.augment_uuid(*tup) for tup in zip(*semantic_infotup)] return annot_semantic_uuid_list
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 make_annotation_uuids(image_uuid_list, bbox_list, theta_list, deterministic=True): try: # Check to make sure bbox input is a tuple-list, not a list-list if len(bbox_list) > 0: try: assert isinstance( bbox_list[0], tuple), 'Bounding boxes must be tuples of ints!' assert isinstance( bbox_list[0][0], int), 'Bounding boxes must be tuples of ints!' except AssertionError as ex: ut.printex(ex) logger.info('bbox_list = %r' % (bbox_list, )) raise annotation_uuid_list = [ ut.augment_uuid(img_uuid, bbox, theta) for img_uuid, bbox, theta in zip( image_uuid_list, bbox_list, theta_list) ] if not deterministic: # Augment determenistic uuid with a random uuid to ensure randomness # (this should be ensured in all hardward situations) annotation_uuid_list = [ ut.augment_uuid(ut.random_uuid(), _uuid) for _uuid in annotation_uuid_list ] except Exception as ex: ut.printex( ex, 'Error building annotation_uuids', '[add_annot]', key_list=['image_uuid_list'], ) raise return annotation_uuid_list
def test_augment_uuid(): # TODO: This is still divergent between python2 and python3 uuid_ = utool.get_zero_uuid() #uuid_ = uuid.uuid1() #uuidhex_data = uuid_.get_bytes() uuidhex_data = uuid_.bytes print('uuidhex_data = %r' % uuidhex_data) hashable_text1 = '[0, 0, 100, 100]' hashable_text2 = '' if six.PY3: hashable_data1 = hashable_text1.encode('utf-8') hashable_data2 = hashable_text2.encode('utf-8') else: hashable_data1 = hashable_text1 hashable_data2 = hashable_text2 augmented_data1 = uuidhex_data + hashable_data1 augmented_data2 = uuidhex_data + hashable_data2 augmented_uuid1_ = utool.hashable_to_uuid(augmented_data1) augmented_uuid2_ = utool.hashable_to_uuid(augmented_data2) print('augmented_data1 =%r' % augmented_data1) print('augmented_data2 =%r' % augmented_data2) struuid_ = utool.hashable_to_uuid(str(uuid_)) print(' uuid_=%r' % (uuid_, )) print('augmented_uuid1_=%r' % (augmented_uuid1_, )) print('augmented_uuid2_=%r' % (augmented_uuid2_, )) print('hash2uuid(uuid_)=%r' % (struuid_, )) # Test what is capable of being augmented import numpy as np augmented_uuid_T1 = utool.augment_uuid(uuid_, hashable_data1) augmented_uuid_T2 = utool.augment_uuid(uuid_, hashable_data2) augmented_uuid_T3 = utool.augment_uuid(uuid_, hashable_data2, hashable_data1) augmented_uuid_T4 = utool.augment_uuid(uuid_, hashable_data1, hashable_data2) augmented_uuid_T5 = utool.augment_uuid(uuid_, [1, 2, 3]) augmented_uuid_T5 = utool.augment_uuid(uuid_, (1, 2, 3)) augmented_uuid_T6 = utool.augment_uuid(uuid_, np.array((1, 2, 3))) print('augmented_uuid_T1=%r' % (augmented_uuid_T1, )) print('augmented_uuid_T2=%r' % (augmented_uuid_T2, )) print('augmented_uuid_T3=%r' % (augmented_uuid_T3, )) print('augmented_uuid_T4=%r' % (augmented_uuid_T4, )) print('augmented_uuid_T5=%r' % (augmented_uuid_T5, )) print('augmented_uuid_T6=%r' % (augmented_uuid_T6, ))
def make_annotation_uuids(image_uuid_list, bbox_list, theta_list, deterministic=True): try: # Check to make sure bbox input is a tuple-list, not a list-list if len(bbox_list) > 0: try: assert isinstance(bbox_list[0], tuple), 'Bounding boxes must be tuples of ints!' assert isinstance(bbox_list[0][0], int), 'Bounding boxes must be tuples of ints!' except AssertionError as ex: ut.printex(ex) print('bbox_list = %r' % (bbox_list,)) raise annotation_uuid_list = [ut.augment_uuid(img_uuid, bbox, theta) for img_uuid, bbox, theta in zip(image_uuid_list, bbox_list, theta_list)] if not deterministic: # Augment determenistic uuid with a random uuid to ensure randomness # (this should be ensured in all hardward situations) annotation_uuid_list = [ut.augment_uuid(ut.random_uuid(), _uuid) for _uuid in annotation_uuid_list] except Exception as ex: ut.printex(ex, 'Error building annotation_uuids', '[add_annot]', key_list=['image_uuid_list']) raise return annotation_uuid_list
def test_augment_uuid(): # TODO: This is still divergent between python2 and python3 uuid_ = utool.get_zero_uuid() #uuid_ = uuid.uuid1() #uuidhex_data = uuid_.get_bytes() uuidhex_data = uuid_.bytes print('uuidhex_data = %r' % uuidhex_data) hashable_text1 = '[0, 0, 100, 100]' hashable_text2 = '' if six.PY3: hashable_data1 = hashable_text1.encode('utf-8') hashable_data2 = hashable_text2.encode('utf-8') else: hashable_data1 = hashable_text1 hashable_data2 = hashable_text2 augmented_data1 = uuidhex_data + hashable_data1 augmented_data2 = uuidhex_data + hashable_data2 augmented_uuid1_ = utool.hashable_to_uuid(augmented_data1) augmented_uuid2_ = utool.hashable_to_uuid(augmented_data2) print('augmented_data1 =%r' % augmented_data1) print('augmented_data2 =%r' % augmented_data2) struuid_ = utool.hashable_to_uuid(str(uuid_)) print(' uuid_=%r' % (uuid_,)) print('augmented_uuid1_=%r' % (augmented_uuid1_,)) print('augmented_uuid2_=%r' % (augmented_uuid2_,)) print('hash2uuid(uuid_)=%r' % (struuid_,)) # Test what is capable of being augmented import numpy as np augmented_uuid_T1 = utool.augment_uuid(uuid_, hashable_data1) augmented_uuid_T2 = utool.augment_uuid(uuid_, hashable_data2) augmented_uuid_T3 = utool.augment_uuid(uuid_, hashable_data2, hashable_data1) augmented_uuid_T4 = utool.augment_uuid(uuid_, hashable_data1, hashable_data2) augmented_uuid_T5 = utool.augment_uuid(uuid_, [1, 2, 3]) augmented_uuid_T5 = utool.augment_uuid(uuid_, (1, 2, 3)) augmented_uuid_T6 = utool.augment_uuid(uuid_, np.array((1, 2, 3))) print('augmented_uuid_T1=%r' % (augmented_uuid_T1,)) print('augmented_uuid_T2=%r' % (augmented_uuid_T2,)) print('augmented_uuid_T3=%r' % (augmented_uuid_T3,)) print('augmented_uuid_T4=%r' % (augmented_uuid_T4,)) print('augmented_uuid_T5=%r' % (augmented_uuid_T5,)) print('augmented_uuid_T6=%r' % (augmented_uuid_T6,))
def make_annot_visual_uuid(visual_infotup): """ Args: visual_infotup (tuple): (image_uuid_list, verts_list, theta_list) Returns: list: annot_visual_uuid_list Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.preproc.preproc_annot import * # NOQA >>> ibs, aid_list = testdata_preproc_annot() >>> visual_infotup = ibs.get_annot_visual_uuid_info(aid_list) >>> annot_visual_uuid_list = make_annot_visual_uuid(visual_infotup) >>> result = str(annot_visual_uuid_list[0]) >>> print(result) 8687dcb6-1f1f-fdd3-8b72-8f36f9f41905 """ assert len(visual_infotup) == 3, 'len=%r' % (len(visual_infotup),) annot_visual_uuid_list = [ut.augment_uuid(*tup) for tup in zip(*visual_infotup)] return annot_visual_uuid_list
def make_annot_visual_uuid(visual_infotup): """ Args: visual_infotup (tuple): (image_uuid_list, verts_list, theta_list) Returns: list: annot_visual_uuid_list Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.preproc.preproc_annot import * # NOQA >>> ibs, aid_list = testdata_preproc_annot() >>> visual_infotup = ibs.get_annot_visual_uuid_info(aid_list) >>> annot_visual_uuid_list = make_annot_visual_uuid(visual_infotup) >>> result = str(annot_visual_uuid_list[0]) >>> print(result) 8687dcb6-1f1f-fdd3-8b72-8f36f9f41905 """ assert len(visual_infotup) == 3, 'len=%r' % (len(visual_infotup), ) annot_visual_uuid_list = [ ut.augment_uuid(*tup) for tup in zip(*visual_infotup) ] return annot_visual_uuid_list
def add_contributors(ibs, tag_list, uuid_list=None, name_first_list=None, name_last_list=None, loc_city_list=None, loc_state_list=None, loc_country_list=None, loc_zip_list=None, notes_list=None): r""" Adds a list of contributors. Returns: contrib_id_list (list): contributor rowids RESTful: Method: POST URL: /api/contributor/ """ import datetime def _valid_zip(_zip, default='00000'): _zip = str(_zip) if len(_zip) == 5 and _zip.isdigit(): return _zip return default if ut.VERBOSE: print('[ibs] adding %d encounters' % len(tag_list)) # Add contributors to database if name_first_list is None: name_first_list = [''] * len(tag_list) if name_last_list is None: name_last_list = [''] * len(tag_list) if loc_city_list is None: loc_city_list = [''] * len(tag_list) if loc_state_list is None: loc_state_list = [''] * len(tag_list) if loc_country_list is None: loc_country_list = [''] * len(tag_list) if loc_zip_list is None: loc_zip_list = [''] * len(tag_list) if notes_list is None: notes_list = [ "Created %s" % (datetime.datetime.now(),) for _ in range(len(tag_list))] loc_zip_list = [ _valid_zip(_zip) for _zip in loc_zip_list] if uuid_list is None: #contrib_rowid_list = ibs.get_contributor_rowid_from_tag(tag_list) #uuid_list = ibs.get_contributor_uuid(contrib_rowid_list) #uuid_list = ibs.get_contributor_uuid(contrib_rowid_list) #uuid_list = [ uuid.uuid4() if uuid_ is None else uuid_ for uuid_ in uuid_list ] # DETERMENISTIC UUIDS zero_uuid = ut.get_zero_uuid() uuid_list = [ut.augment_uuid(zero_uuid, tag) for tag in tag_list] colnames = ['contributor_uuid', 'contributor_tag', 'contributor_name_first', 'contributor_name_last', 'contributor_location_city', 'contributor_location_state', 'contributor_location_country', 'contributor_location_zip', 'contributor_note'] params_iter = zip(uuid_list, tag_list, name_first_list, name_last_list, loc_city_list, loc_state_list, loc_country_list, loc_zip_list, notes_list) get_rowid_from_superkey = ibs.get_contributor_rowid_from_uuid #get_rowid_from_superkey = ibs.get_contributor_rowid_from_tag # ?? is tag a superkey? contrib_id_list = ibs.db.add_cleanly(const.CONTRIBUTOR_TABLE, colnames, params_iter, get_rowid_from_superkey) return contrib_id_list
def add_contributors(ibs, tag_list, uuid_list=None, name_first_list=None, name_last_list=None, loc_city_list=None, loc_state_list=None, loc_country_list=None, loc_zip_list=None, notes_list=None): r""" Adds a list of contributors. Returns: contributor_id_list (list): contributor rowids RESTful: Method: POST URL: /api/contributor/ """ import datetime def _valid_zip(_zip, default='00000'): _zip = str(_zip) if len(_zip) == 5 and _zip.isdigit(): return _zip return default if ut.VERBOSE: print('[ibs] adding %d imagesets' % len(tag_list)) # Add contributors to database if name_first_list is None: name_first_list = [''] * len(tag_list) if name_last_list is None: name_last_list = [''] * len(tag_list) if loc_city_list is None: loc_city_list = [''] * len(tag_list) if loc_state_list is None: loc_state_list = [''] * len(tag_list) if loc_country_list is None: loc_country_list = [''] * len(tag_list) if loc_zip_list is None: loc_zip_list = [''] * len(tag_list) if notes_list is None: notes_list = [ "Created %s" % (datetime.datetime.now(), ) for _ in range(len(tag_list)) ] loc_zip_list = [_valid_zip(_zip) for _zip in loc_zip_list] if uuid_list is None: #contributor_rowid_list = ibs.get_contributor_rowid_from_tag(tag_list) #uuid_list = ibs.get_contributor_uuid(contributor_rowid_list) #uuid_list = ibs.get_contributor_uuid(contributor_rowid_list) #uuid_list = [ uuid.uuid4() if uuid_ is None else uuid_ for uuid_ in uuid_list ] # DETERMENISTIC UUIDS zero_uuid = ut.get_zero_uuid() uuid_list = [ut.augment_uuid(zero_uuid, tag) for tag in tag_list] colnames = [ 'contributor_uuid', 'contributor_tag', 'contributor_name_first', 'contributor_name_last', 'contributor_location_city', 'contributor_location_state', 'contributor_location_country', 'contributor_location_zip', 'contributor_note' ] params_iter = zip(uuid_list, tag_list, name_first_list, name_last_list, loc_city_list, loc_state_list, loc_country_list, loc_zip_list, notes_list) get_rowid_from_superkey = ibs.get_contributor_rowid_from_uuid #get_rowid_from_superkey = ibs.get_contributor_rowid_from_tag # ?? is tag a superkey? contributor_id_list = ibs.db.add_cleanly(const.CONTRIBUTOR_TABLE, colnames, params_iter, get_rowid_from_superkey) return contributor_id_list