-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathevaluate.py
49 lines (40 loc) · 1.39 KB
/
evaluate.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
import torch
from config import Config
from model import Net
from dataset import create_wf_datasets, my_collate_fn
from utils import change_coordinate, seek_model
from detector import Detector
import argparse
from evaluation_metrics import AP
import numpy as np
def evaluate(model):
_, val_dataset = create_wf_datasets(Config.WF_DATASET_DIR)
val_dataloader = torch.utils.data.DataLoader(
val_dataset,
batch_size=1,
num_workers=Config.DATALOADER_WORKER_NUM,
shuffle=True,
collate_fn=my_collate_fn
)
total = len(val_dataloader)
detector = Detector(model)
APs = []
for index, data in enumerate(val_dataloader):
predictions = detector.forward(data)
for i in range(len(predictions)):
if predictions[i] is None:
APs.append(0)
continue
prediction = predictions[i]
gt = np.array(data[1][i])
ap = AP(prediction, gt, 0.5)
APs.append(ap[1.0])
return sum(APs) / len(APs)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='predictor')
parser.add_argument('--model', type=str,
help='model to use, could be epoch number, model file '
'name or model file absolute path')
args = parser.parse_args()
mAP = evaluate(args.model)
print("mAP: {}".format(mAP))