def test(): net, saver, image = load_net_for_inference() with tf.Session() as sess: saver.restore(sess, util.tf.get_latest_ckpt(FLAGS.checkpoint_path)) files = util.io.ls(FLAGS.dataset_dir) for image_name in files: start = time.time() file_path = util.io.join_path(FLAGS.dataset_dir, image_name) image_data = util.img.imread(file_path) image_data = cv2.resize( image_data, (FLAGS.eval_image_width, FLAGS.eval_image_height), interpolation=cv2.INTER_AREA) link_scores, pixel_scores = predict(sess, net, image, image_data) link_time = time.time() #cProfile.runctx('post_process(image_data, pixel_scores, mask_vals)', globals(), locals()) post_process(image_data, link_scores, pixel_scores) post_process_new(image_data, link_scores, pixel_scores) others = time.time() output_file = os.path.expanduser(util.get_temp_path("")) cv2.imwrite(output_file, image_data) sit_time = time.time() print("Score %.3f, postprocess %.3f, sit %.3f" % (link_time - start, others - link_time, sit_time - others))
def test(): file_path = util.io.join_path(FLAGS.dataset_dir, "img_20.jpg") image_data = util.img.imread(file_path) image_data = cv2.resize(image_data, (FLAGS.eval_image_width, FLAGS.eval_image_height), interpolation=cv2.INTER_AREA) link_scores = np.load("link_scores.bin") pixel_scores = np.load("pixel_scores.bin") boxes_old = post_process(image_data, link_scores, pixel_scores) boxes_new = post_process_new(image_data, link_scores, pixel_scores) output_file = os.path.expanduser(util.get_temp_path("")) cv2.imwrite(output_file, image_data) compare_boxes(boxes_old, boxes_new)
def show_images(images, titles=None, shape=None, share_axis=False, bgr2rgb=False, maximized=False, show=True, gray=False, save=False, color_bar=False, path=None, axis_off=False, vertical=False, subtitle=None): plt.close('all') if shape == None: if vertical: shape = (len(images), 1) else: shape = (1, len(images)) shape = list(shape) if shape[0] < 0: shape[0] = (len(images) + shape[1]) / shape[1] elif shape[1] < 0: shape[1] = (len(images + shape[0])) / shape[0] ret_axes = [] ax0 = None plt.figure() for idx, img in enumerate(images): if bgr2rgb: img = util.img.bgr2rgb(img) loc = (idx / shape[1], idx % shape[1]) if idx == 0: ax = plt.subplot2grid(shape, loc) ax0 = ax else: if share_axis: ax = plt.subplot2grid(shape, loc, sharex=ax0, sharey=ax0) else: ax = plt.subplot2grid(shape, loc) if len(np.shape(img)) == 2 and gray: img_ax = ax.imshow(img, cmap='gray') else: img_ax = ax.imshow(img) if len(np.shape(img)) == 2 and color_bar: plt.colorbar(img_ax, ax=ax) if titles != None: ax.set_title(titles[idx]) if axis_off: plt.axis('off') # plt.xticks([]), plt.yticks([]) ret_axes.append(ax) if subtitle is not None: set_subtitle(subtitle) if maximized: maximize_figure() if save: if path is None: path = util.get_temp_path() # raise ValueError('path can not be None when save is True') save_image(path) if show: plt.show() return path