def experiments_voting(**kwargs): experiments_voting_initialize() voting_data() embed = dict(globals(), **locals()) return appf.template('experiments', 'voting', **embed)
def demo(*args, **kwargs): # Return HTML embedded = dict(globals(), **locals()) return appf.template(None, 'demo', **embedded)
def experiments_interest(dbtag1='demo-jasonp', dbtag2='demo-chuck', **kwargs): from uuid import UUID from wbia.other.detectfuncs import general_overlap, general_parse_gt dbtag1 = str(dbtag1) dbtag2 = str(dbtag2) ibs1 = experiment_init_db(dbtag1) ibs2 = experiment_init_db(dbtag2) dbdir1 = ibs1.dbdir dbdir2 = ibs2.dbdir gid_list1 = ibs1.get_valid_gids(reviewed=1) gid_list2 = ibs2.get_valid_gids(reviewed=1) gt_dict1 = general_parse_gt(ibs1, gid_list1) gt_dict2 = general_parse_gt(ibs2, gid_list2) uuid_list1 = sorted(map(str, ibs1.get_image_uuids(gid_list1))) uuid_list2 = sorted(map(str, ibs2.get_image_uuids(gid_list2))) gid_pair_list = [] index1, index2 = 0, 0 stats_global = { 'disagree_interest1': 0, 'disagree_interest2': 0, 'annot1': 0, 'annot2': 0, } while index1 < len(uuid_list1) or index2 < len(uuid_list2): uuid1 = UUID(uuid_list1[index1]) if index1 < len(uuid_list1) else None uuid2 = UUID(uuid_list2[index2]) if index2 < len(uuid_list2) else None if uuid1 is None and uuid2 is None: break gid1 = ibs1.get_image_gids_from_uuid(uuid1) gid2 = ibs2.get_image_gids_from_uuid(uuid2) logger.info('%s %s' % ( index1, index2, )) stats = None if uuid1 is not None and uuid2 is not None: if uuid1 == uuid2: gt_list1 = gt_dict1[uuid1] gt_list2 = gt_dict2[uuid2] stats_global['annot1'] += len(gt_list1) stats_global['annot2'] += len(gt_list2) overlap = general_overlap(gt_list1, gt_list2) if 0 in overlap.shape: index_list1 = [] index_list2 = [] else: index_list1 = np.argmax(overlap, axis=1) index_list2 = np.argmax(overlap, axis=0) pair_list1 = set(enumerate(index_list1)) pair_list2 = set(enumerate(index_list2)) pair_list2 = set([_[::-1] for _ in pair_list2]) pair_union = pair_list1 | pair_list2 pair_intersect = pair_list1 & pair_list2 pair_diff_sym = pair_list1 ^ pair_list2 pair_diff1 = pair_list1 - pair_list2 pair_diff2 = pair_list2 - pair_list1 message_list = [] if len(gt_list1) > 0 and len(gt_list2) == 0: message_list.append('Jason has annotations, Chuck none') if len(gt_list1) == 0 and len(gt_list2) > 0: message_list.append('Chuck has annotations, Jason none') if len(pair_diff1) > 0 and len(pair_diff2) == 0: message_list.append('Jason has additional annotations') if len(pair_diff1) == 0 and len(pair_diff2) > 0: message_list.append('Chuck has additional annotations') if len(pair_diff1) > 0 and len(pair_diff2) > 0: message_list.append('Assignment mismatch') disagree = 0 for index1_, index2_ in pair_intersect: gt1 = gt_list1[index1_] gt2 = gt_list2[index2_] interest1 = gt1['interest'] interest2 = gt2['interest'] if interest1 != interest2: disagree += 1 if interest1 > interest2: stats_global['disagree_interest1'] += 1 if interest2 > interest1: stats_global['disagree_interest2'] += 1 if disagree > 0: message_list.append('Interest mismatch') stats = { 'num_annot1': len(gt_list1), 'num_annot2': len(gt_list2), 'num_interest1': len([_ for _ in gt_list1 if _['interest']]), 'num_interest2': len([_ for _ in gt_list2 if _['interest']]), 'conflict': len(message_list) > 0, 'message': '<br/>'.join(message_list), } else: if uuid1 < uuid2: gid2 = None else: gid1 = None gid_pair_list.append((gid1, gid2, stats)) if gid1 is not None: index1 += 1 if gid2 is not None: index2 += 1 embed = dict(globals(), **locals()) return appf.template('experiments', 'interest', **embed)
def view_experiments(**kwargs): return appf.template('experiments')
def review_detection_html( ibs, image_uuid, result_list, callback_url, callback_method='POST', include_jquery=False, config=None, ): """ Return the detection review interface for a particular image UUID and a list of results for that image. Args: image_uuid (UUID): the UUID of the image you want to review detections for result_list (list of dict): list of detection results returned by the detector callback_url (str): URL that the review form will submit to (action) when the user is complete with their review callback_method (str): HTTP method the review form will submit to (method). Defaults to 'POST' Returns: template (html): json response with the detection web interface in html RESTful: Method: GET URL: /api/review/detect/cnn/yolo/ """ ibs.web_check_uuids(image_uuid_list=[image_uuid]) gid = ibs.get_image_gids_from_uuid(image_uuid) if gid is None: return 'INVALID IMAGE UUID' default_config = { 'autointerest': False, 'interest_bypass': False, 'metadata': True, 'metadata_viewpoint': False, 'metadata_quality': False, 'metadata_flags': True, 'metadata_flags_aoi': True, 'metadata_flags_multiple': False, 'metadata_species': True, 'metadata_label': True, 'metadata_quickhelp': True, 'parts': False, 'modes_rectangle': True, 'modes_diagonal': True, 'modes_diagonal2': True, 'staged': False, } if config is not None: default_config.update(config) gpath = ibs.get_image_thumbpath(gid, ensure_paths=True, draw_annots=False) image = ibs.get_images(gid) image_src = appf.embed_image_html(image) width, height = ibs.get_image_sizes(gid) if width <= 0 or width is None or height <= 0 or height is None: vals = ( image_uuid, width, height, ) raise IOError( 'Image %r for review has either no width or no height (w = %s, h = %s)' % vals ) annotation_list = [] for result in result_list: quality = result.get('quality', None) if quality in [-1, None]: quality = 0 elif quality <= 2: quality = 1 elif quality > 2: quality = 2 viewpoint1 = result.get('viewpoint1', None) viewpoint2 = result.get('viewpoint2', None) viewpoint3 = result.get('viewpoint3', None) if viewpoint1 is None and viewpoint2 is None and viewpoint3 is None: viewpoint = result.get('viewpoint', None) viewpoint1, viewpoint2, viewpoint3 = appf.convert_viewpoint_to_tuple( viewpoint ) annotation_list.append( { 'id': result.get('id', None), 'left': 100.0 * (result.get('left', result['xtl']) / width), 'top': 100.0 * (result.get('top', result['ytl']) / height), 'width': 100.0 * (result['width'] / width), 'height': 100.0 * (result['height'] / height), 'species': result.get('species', result['class']), 'theta': result.get('theta', 0.0), 'viewpoint1': viewpoint1, 'viewpoint2': viewpoint2, 'viewpoint3': viewpoint3, 'quality': quality, 'multiple': 'true' if result.get('multiple', None) == 1 else 'false', 'interest': 'true' if result.get('interest', None) == 1 else 'false', } ) species = KEY_DEFAULTS[SPECIES_KEY] root_path = dirname(abspath(__file__)) css_file_list = [ ['include', 'jquery-ui', 'jquery-ui.min.css'], ['include', 'jquery.ui.rotatable', 'jquery.ui.rotatable.css'], ['css', 'style.css'], ] json_file_list = [ ['include', 'jquery-ui', 'jquery-ui.min.js'], ['include', 'jquery.ui.rotatable', 'jquery.ui.rotatable.min.js'], ['include', 'bbox_annotator_percent.js'], ['javascript', 'script.js'], ['javascript', 'turk-detection.js'], ] if include_jquery: json_file_list = [['javascript', 'jquery.min.js']] + json_file_list EMBEDDED_CSS = '' EMBEDDED_JAVASCRIPT = '' css_template_fmtstr = '<style type="text/css" ia-dependency="css">%s</style>\n' json_template_fmtstr = ( '<script type="text/javascript" ia-dependency="javascript">%s</script>\n' ) for css_file in css_file_list: css_filepath_list = [root_path, 'static'] + css_file with open(join(*css_filepath_list)) as css_file: EMBEDDED_CSS += css_template_fmtstr % (css_file.read(),) for json_file in json_file_list: json_filepath_list = [root_path, 'static'] + json_file with open(join(*json_filepath_list)) as json_file: EMBEDDED_JAVASCRIPT += json_template_fmtstr % (json_file.read(),) species_rowids = ibs._get_all_species_rowids() species_nice_list = ibs.get_species_nice(species_rowids) combined_list = sorted(zip(species_nice_list, species_rowids)) species_nice_list = [combined[0] for combined in combined_list] species_rowids = [combined[1] for combined in combined_list] species_text_list = ibs.get_species_texts(species_rowids) species_list = list(zip(species_nice_list, species_text_list)) species_list = [('Unspecified', const.UNKNOWN)] + species_list # Collect mapping of species to parts aid_list = ibs.get_valid_aids() part_species_rowid_list = ibs.get_annot_species_rowids(aid_list) part_species_text_list = ibs.get_species_texts(part_species_rowid_list) part_rowids_list = ibs.get_annot_part_rowids(aid_list) part_types_list = map(ibs.get_part_types, part_rowids_list) zipped = list(zip(part_species_text_list, part_types_list)) species_part_dict = {const.UNKNOWN: set([])} for part_species_text, part_type_list in zipped: if part_species_text not in species_part_dict: species_part_dict[part_species_text] = set([const.UNKNOWN]) for part_type in part_type_list: species_part_dict[part_species_text].add(part_type) species_part_dict[const.UNKNOWN].add(part_type) # Add any images that did not get added because they aren't assigned any annotations for species_text in species_text_list: if species_text not in species_part_dict: species_part_dict[species_text] = set([const.UNKNOWN]) for key in species_part_dict: species_part_dict[key] = sorted(list(species_part_dict[key])) species_part_dict_json = json.dumps(species_part_dict) orientation_flag = '0' if species is not None and 'zebra' in species: orientation_flag = '1' settings_key_list = [ ('ia-detection-setting-orientation', orientation_flag), ('ia-detection-setting-parts-assignments', '1'), ('ia-detection-setting-toggle-annotations', '1'), ('ia-detection-setting-toggle-parts', '0'), ('ia-detection-setting-parts-show', '0'), ('ia-detection-setting-parts-hide', '0'), ] settings = { settings_key: request.cookies.get(settings_key, settings_default) == '1' for (settings_key, settings_default) in settings_key_list } return appf.template( 'turk', 'detection_insert', gid=gid, refer_aid=None, species=species, image_path=gpath, image_src=image_src, config=default_config, settings=settings, annotation_list=annotation_list, species_list=species_list, species_part_dict_json=species_part_dict_json, callback_url=callback_url, callback_method=callback_method, EMBEDDED_CSS=EMBEDDED_CSS, EMBEDDED_JAVASCRIPT=EMBEDDED_JAVASCRIPT, )