2
2
import PIL
3
3
import numpy as np
4
4
from multiprocessing import Pool
5
+ from functools import partial
6
+ import cfgs .config as cfg
7
+ import cv2
5
8
6
9
7
10
def mkdir (path , max_depth = 3 ):
@@ -13,6 +16,12 @@ def mkdir(path, max_depth=3):
13
16
os .mkdir (path )
14
17
15
18
19
+ def image_resize (im , size_index ):
20
+ w , h = cfg .multi_scale_inp_size [size_index ]
21
+ im = cv2 .resize (im , (w , h ))
22
+ return im
23
+
24
+
16
25
class ImageDataset (object ):
17
26
def __init__ (self , name , datadir , batch_size , im_processor , processes = 3 , shuffle = True , dst_size = None ):
18
27
self ._name = name
@@ -38,12 +47,13 @@ def __init__(self, name, datadir, batch_size, im_processor, processes=3, shuffle
38
47
self .gen = None
39
48
self ._im_processor = im_processor
40
49
41
- def next_batch (self ):
50
+ def next_batch (self , size_index ):
42
51
batch = {'images' : [], 'gt_boxes' : [], 'gt_classes' : [], 'dontcare' : [], 'origin_im' : []}
43
52
i = 0
44
53
while i < self .batch_size :
45
54
try :
46
55
images , gt_boxes , classes , dontcare , origin_im = next (self .gen )
56
+ images = image_resize (images , size_index )
47
57
batch ['images' ].append (images )
48
58
batch ['gt_boxes' ].append (gt_boxes )
49
59
batch ['gt_classes' ].append (classes )
@@ -54,7 +64,7 @@ def next_batch(self):
54
64
indexes = np .arange (len (self .image_names ), dtype = np .int )
55
65
if self ._shuffle :
56
66
np .random .shuffle (indexes )
57
- self .gen = self .pool .imap (self ._im_processor ,
67
+ self .gen = self .pool .imap (partial ( self ._im_processor , size_index = size_index ) ,
58
68
([self .image_names [i ], self .get_annotation (i ), self .dst_size ] for i in indexes ),
59
69
chunksize = self .batch_size )
60
70
self ._epoch += 1
0 commit comments