def precision_score(self, y_true, y_pred, **kwargs): nms_flag = kwargs.pop('nms_flag', True) if nms_flag: bboxes = predict_nms_boxes(y_pred) else: bboxes = convert_boxes(y_pred) gt_bboxes = convert_boxes(y_true) score = cal_precision(gt_bboxes, bboxes) return score
def score(self, y_true, y_pred, **kwargs): """Compute Recall for a given predicted bboxes""" nms_flag = kwargs.pop('nms_flag', True) if nms_flag: bboxes = predict_nms_boxes(y_pred) else: bboxes = convert_boxes(y_pred) gt_bboxes = convert_boxes(y_true) score = cal_recall(gt_bboxes, bboxes) return score
nms_flag = True hp_d = dict() # hp_d['image_mean'] = image_mean hp_d['batch_size'] = 16 hp_d['nms_flag'] = nms_flag """ 3. Build graph, load weights, initialize a session and start test """ # Initialize graph = tf.get_default_graph() config = tf.ConfigProto() config.gpu_options.allow_growth = True model = ConvNet([IM_SIZE[0], IM_SIZE[1], 3], NUM_CLASS, anchors, grid_size=(IM_SIZE[0] // 32, IM_SIZE[1] // 32)) saver = tf.train.Saver() sess = tf.Session(graph=graph, config=config) saver.restore(sess, '/tmp/model.ckpt') test_y_pred = model.predict(sess, test_set, **hp_d) """ 4. Draw boxes on image """ draw_dir = os.path.join(test_dir, 'draws') for idx, (img, y_pred) in enumerate(zip(test_set.images, test_y_pred)): draw_path = os.path.join(draw_dir, '{}_test_images.png'.format(idx + 1)) if nms_flag: bboxes = predict_nms_boxes(y_pred) else: bboxes = convert_boxes(y_pred) bboxes = bboxes[np.nonzero(np.any(bboxes > 0, axis=1))] boxed_img = draw_pred_boxes(img, bboxes, class_map, score=True) cv2.imwrite(draw_path, boxed_img)
print('Test performance: {}'.format(test_score)) """ 4. Draw boxes on image """ draw_dir = os.path.join(test_dir, 'draws') # FIXME im_dir = os.path.join(test_dir, 'images') # FIXME im_paths = [] im_paths.extend(glob.glob(os.path.join(im_dir, '*.jpg'))) for idx, (img, y_pred, im_path) in enumerate(zip(test_set.images, test_y_pred, im_paths)): print("im_path : ", im_path) name = im_path.split('\\')[-1] print("name : ", name) draw_path = os.path.join(draw_dir, name) if nms_flag: bboxes = predict_nms_boxes(y_pred, conf_thres=0.5, iou_thres=0.5) else: bboxes = convert_boxes(y_pred) bboxes = bboxes[np.nonzero(np.any(bboxes > 0, axis=1))] boxed_img = draw_pred_boxes(img, bboxes, class_map) # print(draw_path) cv2.imwrite(draw_path, boxed_img) cv2.imshow("img", img.astype(np.uint8)) cv2.imshow("output", boxed_img.astype(np.uint8)) cv2.waitKey(0)