-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostprocess.py
executable file
·58 lines (41 loc) · 1.47 KB
/
postprocess.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
56
57
58
"""Evaluation for paa"""
import os
import numpy as np
from PIL import Image
from src.coco_eval import metrics
from src.model_utils.config import config
def get_pred(result_path, img_id):
boxes_file = os.path.join(result_path, img_id + '_0.bin')
scores_file = os.path.join(result_path, img_id + '_1.bin')
boxes = np.fromfile(boxes_file, dtype=np.float32).reshape(67995, 4)
scores = np.fromfile(scores_file, dtype=np.float32).reshape(67995, 81)
return boxes, scores
def get_img_size(file_name):
img = Image.open(file_name)
return img.size
def get_img_id(img_id_file):
f = open(img_id_file)
lines = f.readlines()
ids = []
for line in lines:
ids.append(int(line))
return ids
def cal_acc(result_path, img_path, img_id_file):
ids = get_img_id(img_id_file)
imgs = os.listdir(img_path)
pred_data = []
for img in imgs:
img_id = img.split('.')[0]
if int(img_id) not in ids:
continue
boxes, box_scores = get_pred(result_path, img_id)
w, h = get_img_size(os.path.join(img_path, img))
img_shape = np.array((h, w), dtype=np.float32)
pred_data.append({"boxes": boxes,
"box_scores": box_scores,
"img_id": int(img_id),
"image_shape": img_shape})
mAP = metrics(pred_data)
print(f"mAP: {mAP}")
if __name__ == '__main__':
cal_acc(config.result_path, config.img_path, config.img_id_file)