forked from Kevinz-code/CSRA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.py
58 lines (47 loc) · 2.34 KB
/
eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import argparse
import torch
import numpy as np
import json
from tqdm import tqdm
from .cal_mAP import json_map
from .cal_PR import json_metric, metric, json_metric_top3
voc_classes = ("aeroplane", "bicycle", "bird", "boat", "bottle",
"bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant",
"sheep", "sofa", "train", "tvmonitor")
coco_classes = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
'train', 'truck', 'boat', 'traffic_light', 'fire_hydrant',
'stop_sign', 'parking_meter', 'bench', 'bird', 'cat', 'dog',
'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
'skis', 'snowboard', 'sports_ball', 'kite', 'baseball_bat',
'baseball_glove', 'skateboard', 'surfboard', 'tennis_racket',
'bottle', 'wine_glass', 'cup', 'fork', 'knife', 'spoon', 'bowl',
'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot',
'hot_dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
'potted_plant', 'bed', 'dining_table', 'toilet', 'tv', 'laptop',
'mouse', 'remote', 'keyboard', 'cell_phone', 'microwave',
'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock',
'vase', 'scissors', 'teddy_bear', 'hair_drier', 'toothbrush')
wider_classes = (
"Male","longHair","sunglass","Hat","Tshiirt","longSleeve","formal",
"shorts","jeans","longPants","skirt","faceMask", "logo","stripe")
class_dict = {
"voc07": voc_classes,
"voc12": voc_classes,
"coco": coco_classes,
"wider": wider_classes,
}
def evaluation(result, types, ann_path):
print("Evaluation")
classes = class_dict[types]
aps = np.zeros(len(classes), dtype=np.float64)
ann_json = json.load(open(ann_path, "r"))
pred_json = result
for i, _ in enumerate(tqdm(classes)):
ap = json_map(i, pred_json, ann_json, types)
aps[i] = ap
OP, OR, OF1, CP, CR, CF1 = json_metric(pred_json, ann_json, len(classes), types)
print("mAP: {:4f}".format(np.mean(aps)))
print("CP: {:4f}, CR: {:4f}, CF1 :{:4F}".format(CP, CR, CF1))
print("OP: {:4f}, OR: {:4f}, OF1 {:4F}".format(OP, OR, OF1))