def show_all_images(): with open(json_path, 'r') as f: data = json.loads(f.readline().strip()) details = Detail(ann_file, im_dir, pahse) for im, val in data.items(): # input = raw_input('\nnext image? (y/n): ') # if input in ['n', 'no']: # while True: # user_in = raw_input("Enter 'q' to quit: ") # if user_in in ['q', 'quit']: # return while True: input = raw_input( '\nn (next image), c (close all figures), q (quit): ') if input == 'c': plt.close('all') if input == 'n': break if input == 'q': return fig, ax = plt.subplots() plt.ion() plt.show() im = str(im) details.showImg(im, ax=ax, wait=True) ax.set_title(im) plot_points(val, fig, ax) fig.canvas.mpl_connect("motion_notify_event", hover) plt.draw() plt.pause(0.001) log_writer(fig, im)
def show_from_point_on(start_image, index_mode=False, params={}): """index_mode == True --> start_image is the index of the starting point by index """ json_path = params['json_path'] ann_file = params['ann_file'] im_dir = params['im_dir'] phase = params['phase'] log_table_path = params['log_table_path'] merge_level = params['merge_level'] with open(json_path, 'r') as f: data = json.loads(f.readline().strip()) details = Detail(ann_file, im_dir, phase) found_starting_point = False for idx, (im, val) in enumerate(data.items()): if not found_starting_point: if index_mode: if idx >= start_image: found_starting_point = True else: continue else: if im == start_image: found_starting_point = True else: continue while True: input = raw_input( '\nn (next image), c (close all figures), q (quit): ') if input == 'c': plt.close('all') if input == 'n': break if input == 'q': return fig, ax = plt.subplots() plt.ion() plt.show() im = str(im) details.showImg(im, ax=ax, wait=True) ax.set_title(im) plot_points(val, fig, ax, merge_level) fig.canvas.mpl_connect("motion_notify_event", hover) plt.draw() plt.pause(0.001) log_writer(fig, im, log_table_path)
def show_all_errors_for_class(cls, params): json_path = params['json_path'] ann_file = params['ann_file'] im_dir = params['im_dir'] phase = params['phase'] log_table_path = params['log_table_path'] merge_level = params['merge_level'] print("showing errors for class {}".format(cls)) with open(json_path, 'r') as f: data = json.loads(f.readline().strip()) details = Detail(ann_file, im_dir, phase) for im, val in data.items(): # TODO: implement contains_error for json with just 0,1 predictions and annotations # do it by using the pascal_gt.json for getting the ground truth class # do same in visualize errors by class if not contains_error(val, cls): continue while True: input = raw_input( '\nn (next image), c (close all figures), q (quit): ') if input == 'c': plt.close('all') if input == 'n': break if input == 'q': return fig, ax = plt.subplots() plt.ion() plt.show() im = str(im) details.showImg(im, ax=ax, wait=True) ax.set_title(im) plot_points(val, fig, ax, merge_level) fig.canvas.mpl_connect("motion_notify_event", hover) plt.draw() plt.pause(0.001) log_writer(fig, im, log_table_path)
def show_1_image(im, params): json_path = params['json_path'] ann_file = params['ann_file'] im_dir = params['im_dir'] phase = params['phase'] log_table_path = params['log_table_path'] merge_level = params['merge_level'] with open(json_path, 'r') as f: data = json.loads(f.readline().strip()) details = Detail(ann_file, im_dir, phase) while True: try: val = data[im] fig, ax = plt.subplots() plt.ion() plt.show() im = str(im) details.showImg(im, ax=ax, wait=True) ax.set_title(im) plot_points(val, fig, ax, merge_level) fig.canvas.mpl_connect("motion_notify_event", hover) plt.draw() plt.pause(0.001) log_writer(fig, im, log_table_path) except KeyError: print("[-] Error: Invalid image name") while True: user_input = raw_input( "n (another image), c (close all figures), q (quit): ") if user_input == 'q': return if user_input == 'n': im = raw_input("Enter image name: ") break if user_input == 'c': plt.close('all')
def show_all_images_containing_given_class(cls, params): json_path = params['json_path'] ann_file = params['ann_file'] im_dir = params['im_dir'] phase = params['phase'] log_table_path = params['log_table_path'] merge_level = params['merge_level'] print("showing images for class {}".format(cls)) with open(json_path, 'r') as f: data = json.loads(f.readline().strip()) details = Detail(ann_file, im_dir, phase) for im, val in data.items(): if not contains_class(val, cls): continue while True: input = raw_input( '\nn (next image), c (close all figures), q (quit): ') if input == 'c': plt.close('all') if input == 'n': break if input == 'q': return fig, ax = plt.subplots() plt.ion() plt.show() im = str(im) details.showImg(im, ax=ax, wait=True) ax.set_title(im) plot_points(val, fig, ax, merge_level) fig.canvas.mpl_connect("motion_notify_event", hover) plt.draw() plt.pause(0.001) log_writer(fig, im, log_table_path)
# for cat in cats: # print('\t{name} ({category_id}): \t{supercategory}'.format(**cat)) # print('%d images in the current phase (%s)' % (len(details.getImgs()), details.phase)) # imgs = details.getImgs(cats=['person', 'motorbike']); # print('%d images contain both persons and motorbikes' % len(imgs)) _, axarr = plt.subplots(1,2) # img = imgs[random.randrange(len(imgs))] img = '2008_007573' pt = [261, 119] cat_idx = 8 details.showImg(img, ax=axarr[0], wait=True) # cats = details.getCats(imgs=img) # print("") # print(['%s (%d) : %s' % (cat['name'], cat['category_id'], cat['supercategory']) for cat in cats]) print "****" print "{} --> ".format(cat_idx) + CLASS_NAMES[cat_idx] # mask # mask = details.getMask(img, cat='person', instance='#0', show=False) mask = details.getMask(img, show=False) mycmap = get_rand_color_map() mycmap.set_under(alpha=0.0) nonzero = np.unique(mask[np.nonzero(mask)])