forked from yhenon/pytorch-retinanet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coco_validation.py
49 lines (33 loc) · 1.43 KB
/
coco_validation.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 argparse
import torch
from torchvision import transforms
from retinanet import model
from retinanet.dataloader import CocoDataset, Resizer, Normalizer
from retinanet import coco_eval
assert torch.__version__.split('.')[0] == '1'
print('CUDA available: {}'.format(torch.cuda.is_available()))
def main(args=None):
parser = argparse.ArgumentParser(description='Simple training script for training a RetinaNet network.')
parser.add_argument('--coco_path', help='Path to COCO directory')
parser.add_argument('--model_path', help='Path to model', type=str)
parser = parser.parse_args(args)
dataset_val = CocoDataset(parser.coco_path, set_name='val2017',
transform=transforms.Compose([Normalizer(), Resizer()]))
# Create the model
retinanet = model.resnet50(num_classes=dataset_val.num_classes(), pretrained=True)
use_gpu = True
if use_gpu:
if torch.cuda.is_available():
retinanet = retinanet.cuda()
if torch.cuda.is_available():
retinanet.load_state_dict(torch.load(parser.model_path))
retinanet = torch.nn.DataParallel(retinanet).cuda()
else:
retinanet.load_state_dict(torch.load(parser.model_path))
retinanet = torch.nn.DataParallel(retinanet)
retinanet.training = False
retinanet.eval()
retinanet.module.freeze_bn()
coco_eval.evaluate_coco(dataset_val, retinanet)
if __name__ == '__main__':
main()