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)