2
2
import cv2
3
3
import numpy as np
4
4
import pickle
5
+ import argparse
5
6
6
7
from darknet import Darknet19
7
8
import utils .yolo as yolo_utils
@@ -18,6 +19,13 @@ def preprocess(fname):
18
19
return image , im_data
19
20
20
21
22
+ parser = argparse .ArgumentParser (description = 'PyTorch Yolo' )
23
+ parser .add_argument ('--image_size_index' , type = int , default = 0 ,
24
+ metavar = 'image_size_index' ,
25
+ help = 'setting images size index 0:320, 1:352, 2:384, 3:416, 4:448, 5:480, 6:512, 7:544, 8:576' )
26
+ args = parser .parse_args ()
27
+
28
+
21
29
# hyper-parameters
22
30
# ------------
23
31
imdb_name = cfg .imdb_test
@@ -44,10 +52,11 @@ def test_net(net, imdb, max_per_image=300, thresh=0.5, vis=False):
44
52
# timers
45
53
_t = {'im_detect' : Timer (), 'misc' : Timer ()}
46
54
det_file = os .path .join (output_dir , 'detections.pkl' )
55
+ size_index = args .image_size_index
47
56
48
57
for i in range (num_images ):
49
58
50
- batch = imdb .next_batch ()
59
+ batch = imdb .next_batch (size_index = size_index )
51
60
ori_im = batch ['origin_im' ][0 ]
52
61
im_data = net_utils .np_to_variable (batch ['images' ], is_cuda = True ,
53
62
volatile = True ).permute (0 , 3 , 1 , 2 )
@@ -65,7 +74,9 @@ def test_net(net, imdb, max_per_image=300, thresh=0.5, vis=False):
65
74
prob_pred ,
66
75
ori_im .shape ,
67
76
cfg ,
68
- thresh )
77
+ thresh ,
78
+ size_index
79
+ )
69
80
detect_time = _t ['im_detect' ].toc ()
70
81
71
82
_t ['misc' ].tic ()
@@ -122,7 +133,7 @@ def test_net(net, imdb, max_per_image=300, thresh=0.5, vis=False):
122
133
# data loader
123
134
imdb = VOCDataset (imdb_name , cfg .DATA_DIR , cfg .batch_size ,
124
135
yolo_utils .preprocess_test ,
125
- processes = 2 , shuffle = False , dst_size = cfg .inp_size )
136
+ processes = 2 , shuffle = False , dst_size = cfg .multi_scale_inp_size )
126
137
127
138
net = Darknet19 ()
128
139
net_utils .load_net (trained_model , net )
0 commit comments