This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 665
/
csv_validation.py
52 lines (37 loc) · 1.9 KB
/
csv_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
50
51
52
import argparse
import torch
from torchvision import transforms
from retinanet import model
from retinanet.dataloader import CSVDataset, Resizer, Normalizer
from retinanet import csv_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('--csv_annotations_path', help='Path to CSV annotations')
parser.add_argument('--model_path', help='Path to model', type=str)
parser.add_argument('--images_path',help='Path to images directory',type=str)
parser.add_argument('--class_list_path',help='Path to classlist csv',type=str)
parser.add_argument('--iou_threshold',help='IOU threshold used for evaluation',type=str, default='0.5')
parser = parser.parse_args(args)
#dataset_val = CocoDataset(parser.coco_path, set_name='val2017',transform=transforms.Compose([Normalizer(), Resizer()]))
dataset_val = CSVDataset(parser.csv_annotations_path,parser.class_list_path,transform=transforms.Compose([Normalizer(), Resizer()]))
# Create the model
#retinanet = model.resnet50(num_classes=dataset_val.num_classes(), pretrained=True)
retinanet=torch.load(parser.model_path)
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()
print(csv_eval.evaluate(dataset_val, retinanet,iou_threshold=float(parser.iou_threshold)))
if __name__ == '__main__':
main()