1
- import cPickle
1
+ import pickle
2
2
import os
3
3
import uuid
4
4
import cv2
9
9
10
10
# from functools import partial
11
11
12
- from imdb import ImageDataset
13
- from voc_eval import voc_eval
12
+ from . imdb import ImageDataset
13
+ from . voc_eval import voc_eval
14
14
# from utils.yolo import preprocess_train
15
15
16
16
@@ -30,7 +30,7 @@ def __init__(self, imdb_name, datadir, batch_size, im_processor, processes=3, sh
30
30
'cow' , 'diningtable' , 'dog' , 'horse' ,
31
31
'motorbike' , 'person' , 'pottedplant' ,
32
32
'sheep' , 'sofa' , 'train' , 'tvmonitor' )
33
- self ._class_to_ind = dict (zip (self .classes , range (self .num_classes )))
33
+ self ._class_to_ind = dict (list ( zip (self .classes , list ( range (self .num_classes )) )))
34
34
self ._image_ext = '.jpg'
35
35
36
36
self ._salt = str (uuid .uuid4 ())
@@ -102,15 +102,15 @@ def _load_pascal_annotations(self):
102
102
cache_file = os .path .join (self .cache_path , self .name + '_gt_roidb.pkl' )
103
103
if os .path .exists (cache_file ):
104
104
with open (cache_file , 'rb' ) as fid :
105
- roidb = cPickle .load (fid )
106
- print '{} gt roidb loaded from {}' .format (self .name , cache_file )
105
+ roidb = pickle .load (fid )
106
+ print ( '{} gt roidb loaded from {}' .format (self .name , cache_file ) )
107
107
return roidb
108
108
109
109
gt_roidb = [self ._annotation_from_index (index )
110
110
for index in self .image_indexes ]
111
111
with open (cache_file , 'wb' ) as fid :
112
- cPickle .dump (gt_roidb , fid , cPickle .HIGHEST_PROTOCOL )
113
- print 'wrote gt roidb to {}' .format (cache_file )
112
+ pickle .dump (gt_roidb , fid , pickle .HIGHEST_PROTOCOL )
113
+ print ( 'wrote gt roidb to {}' .format (cache_file ) )
114
114
115
115
return gt_roidb
116
116
@@ -180,15 +180,15 @@ def _write_voc_results_file(self, all_boxes):
180
180
for cls_ind , cls in enumerate (self .classes ):
181
181
if cls == '__background__' :
182
182
continue
183
- print 'Writing {} VOC results file' .format (cls )
183
+ print ( 'Writing {} VOC results file' .format (cls ) )
184
184
filename = self ._get_voc_results_file_template ().format (cls )
185
185
with open (filename , 'wt' ) as f :
186
186
for im_ind , index in enumerate (self .image_indexes ):
187
187
dets = all_boxes [cls_ind ][im_ind ]
188
188
if dets == []:
189
189
continue
190
190
# the VOCdevkit expects 1-based indices
191
- for k in xrange (dets .shape [0 ]):
191
+ for k in range (dets .shape [0 ]):
192
192
f .write ('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n ' .
193
193
format (index , dets [k , - 1 ],
194
194
dets [k , 0 ] + 1 , dets [k , 1 ] + 1 ,
@@ -210,7 +210,7 @@ def _do_python_eval(self, output_dir='output'):
210
210
aps = []
211
211
# The PASCAL VOC metric changed in 2010
212
212
use_07_metric = True if int (self ._year ) < 2010 else False
213
- print 'VOC07 metric? ' + ('Yes' if use_07_metric else 'No' )
213
+ print ( 'VOC07 metric? ' + ('Yes' if use_07_metric else 'No' ) )
214
214
if output_dir is not None and not os .path .isdir (output_dir ):
215
215
os .mkdir (output_dir )
216
216
for i , cls in enumerate (self ._classes ):
@@ -221,16 +221,16 @@ def _do_python_eval(self, output_dir='output'):
221
221
filename , annopath , imagesetfile , cls , cachedir , ovthresh = 0.5 ,
222
222
use_07_metric = use_07_metric )
223
223
aps += [ap ]
224
- print ('AP for {} = {:.4f}' .format (cls , ap ))
224
+ print (( 'AP for {} = {:.4f}' .format (cls , ap ) ))
225
225
if output_dir is not None :
226
226
with open (os .path .join (output_dir , cls + '_pr.pkl' ), 'w' ) as f :
227
- cPickle .dump ({'rec' : rec , 'prec' : prec , 'ap' : ap }, f )
228
- print ('Mean AP = {:.4f}' .format (np .mean (aps )))
227
+ pickle .dump ({'rec' : rec , 'prec' : prec , 'ap' : ap }, f )
228
+ print (( 'Mean AP = {:.4f}' .format (np .mean (aps ) )))
229
229
print ('~~~~~~~~' )
230
230
print ('Results:' )
231
231
for ap in aps :
232
- print ('{:.3f}' .format (ap ))
233
- print ('{:.3f}' .format (np .mean (aps )))
232
+ print (( '{:.3f}' .format (ap ) ))
233
+ print (( '{:.3f}' .format (np .mean (aps ) )))
234
234
print ('~~~~~~~~' )
235
235
print ('' )
236
236
print ('--------------------------------------------------------------' )
0 commit comments