MCPcopy Index your code
hub / github.com/explainingai-code/FasterRCNN-PyTorch / evaluate_map

Function evaluate_map

tools/infer.py:263–303  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

261
262
263def evaluate_map(args):
264 faster_rcnn_model, voc, test_dataset = load_model_and_dataset(args)
265 gts = []
266 preds = []
267 for im, target, fname in tqdm(test_dataset):
268 im_name = fname
269 im = im.float().to(device)
270 target_boxes = target['bboxes'].float().to(device)[0]
271 target_labels = target['labels'].long().to(device)[0]
272 rpn_output, frcnn_output = faster_rcnn_model(im, None)
273
274 boxes = frcnn_output['boxes']
275 labels = frcnn_output['labels']
276 scores = frcnn_output['scores']
277
278 pred_boxes = {}
279 gt_boxes = {}
280 for label_name in voc.label2idx:
281 pred_boxes[label_name] = []
282 gt_boxes[label_name] = []
283
284 for idx, box in enumerate(boxes):
285 x1, y1, x2, y2 = box.detach().cpu().numpy()
286 label = labels[idx].detach().cpu().item()
287 score = scores[idx].detach().cpu().item()
288 label_name = voc.idx2label[label]
289 pred_boxes[label_name].append([x1, y1, x2, y2, score])
290 for idx, box in enumerate(target_boxes):
291 x1, y1, x2, y2 = box.detach().cpu().numpy()
292 label = target_labels[idx].detach().cpu().item()
293 label_name = voc.idx2label[label]
294 gt_boxes[label_name].append([x1, y1, x2, y2])
295
296 gts.append(gt_boxes)
297 preds.append(pred_boxes)
298
299 mean_ap, all_aps = compute_map(preds, gts, method='interp')
300 print('Class Wise Average Precisions')
301 for idx in range(len(voc.idx2label)):
302 print('AP for class {} = {:.4f}'.format(voc.idx2label[idx], all_aps[voc.idx2label[idx]]))
303 print('Mean Average Precision : {:.4f}'.format(mean_ap))
304
305
306if __name__ == '__main__':

Callers 1

infer.pyFile · 0.70

Calls 2

load_model_and_datasetFunction · 0.70
compute_mapFunction · 0.70

Tested by

no test coverage detected