MCPcopy Create free account
hub / github.com/EryiXie/PlaneRecNet / evaluate

Function evaluate

eval.py:63–130  ·  view source on GitHub ↗
(net: PlaneRecNet, dataset, during_training=False, eval_nums=-1)

Source from the content-addressed store, hash-verified

61iou_thresholds = [x / 100 for x in range(50, 100, 5)]
62
63def evaluate(net: PlaneRecNet, dataset, during_training=False, eval_nums=-1):
64 frame_times = MovingAverage()
65 eval_nums = len(dataset) - 1 if eval_nums < 0 else min(eval_nums, len(dataset))
66 progress_bar = ProgressBar(30, eval_nums)
67
68 print()
69
70 dataset_indices = list(range(len(dataset)))
71 random.shuffle(dataset_indices)
72 dataset_indices = dataset_indices[:eval_nums]
73
74 infos = []
75 ap_data = {
76 'box': [APDataObject() for _ in iou_thresholds],
77 'mask': [APDataObject() for _ in iou_thresholds]
78 }
79
80 try:
81 # Main eval loop
82 for it, image_idx in enumerate(dataset_indices):
83 timer.reset()
84
85 image, gt_instances, gt_depth = dataset.pull_item(image_idx)
86 batch = Variable(image.unsqueeze(0)).cuda()
87
88 batched_result = net(batch) # if batch_size = 1, result = batched_result[0]
89 result = batched_result[0]
90
91 # TODO: this dict looping is not a good practice, python < 3.6 doesn't keep keys/values in same order as declared.
92 gt_masks, gt_boxes, gt_classes, gt_planes, k_matrices = [v.cuda() for k, v in gt_instances.items()]
93 pred_masks, pred_boxes, pred_classes, pred_scores, pred_depth = [v for k, v in result.items()]
94
95 gt_depth = gt_depth.cuda()
96 depth_error_per_frame = compute_depth_metrics(pred_depth, gt_depth, median_scaling=True)
97 infos.append(depth_error_per_frame)
98
99 if pred_masks is not None:
100 pred_masks = pred_masks.float()
101 gt_masks = gt_masks.float()
102 compute_segmentation_metrics(ap_data, gt_masks, gt_boxes, gt_classes, pred_masks, pred_boxes, pred_classes, pred_scores)
103
104 # First couple of images take longer because we're constructing the graph.
105 # Since that's technically initialization, don't include those in the FPS calculations.
106 if it > 1:
107 frame_times.add(timer.total_time())
108
109 if not args.no_bar:
110 if it > 1:
111 fps = 1000 / frame_times.get_avg()
112 else:
113 fps = 0
114 progress = (it+1) / eval_nums * 100
115 progress_bar.set_val(it+1)
116 print('\rProcessing Images %s %6d / %6d (%5.2f%%) %5.2f fps '
117 % (repr(progress_bar), it+1, eval_nums, progress, fps), end='')
118 calc_map(ap_data)
119 infos = np.asarray(infos, dtype=np.double)
120 infos = infos.sum(axis=0)/infos.shape[0]

Callers 1

eval.pyFile · 0.85

Calls 12

addMethod · 0.95
get_avgMethod · 0.95
set_valMethod · 0.95
MovingAverageClass · 0.90
ProgressBarClass · 0.90
APDataObjectClass · 0.85
compute_depth_metricsFunction · 0.85
calc_mapFunction · 0.85
resetMethod · 0.80
pull_itemMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected