-
Notifications
You must be signed in to change notification settings - Fork 77
/
eval.py
55 lines (45 loc) · 1.69 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 importlib
import fire
import os
import copy
import torch
from _path_init import *
from visualDet3D.networks.utils.registry import DETECTOR_DICT, DATASET_DICT, PIPELINE_DICT
from visualDet3D.utils.utils import cfg_from_file
print('CUDA available: {}'.format(torch.cuda.is_available()))
def main(config:str="config/config.py",
gpu:int=0,
checkpoint_path:str="retinanet_79.pth",
split_to_test:str='validation'):
# Read Config
cfg = cfg_from_file(config)
# Force GPU selection in command line
cfg.trainer.gpu = gpu
torch.cuda.set_device(cfg.trainer.gpu)
# Set up dataset and dataloader
is_test_train = split_to_test == 'training'
if split_to_test == 'training':
dataset_name = cfg.data.train_dataset
elif split_to_test == 'test':
dataset_name = cfg.data.test_dataset
cfg.is_running_test_set = True
else:
dataset_name = cfg.data.val_dataset
dataset = DATASET_DICT[dataset_name](cfg, split_to_test)
# Create the model
detector = DETECTOR_DICT[cfg.detector.name](cfg.detector)
detector = detector.cuda()
state_dict = torch.load(checkpoint_path, map_location='cuda:{}'.format(cfg.trainer.gpu))
new_dict = state_dict.copy()
detector.load_state_dict(new_dict, strict=False)
detector.eval()
if 'evaluate_func' in cfg.trainer:
evaluate_detection = PIPELINE_DICT[cfg.trainer.evaluate_func]
print("Found evaluate function")
else:
raise KeyError("evluate_func not found in Config")
# Run evaluation
evaluate_detection(cfg, detector, dataset, None, 0, result_path_split=split_to_test)
print('finish')
if __name__ == '__main__':
fire.Fire(main)