@@ -36,7 +36,8 @@ def __init__(self,
3636 device_id ,
3737 num_gpus ,
3838 deterministic = False ,
39- dali_cpu = True ):
39+ dali_cpu = True ,
40+ training = True ):
4041
4142 kwargs = dict ()
4243 if deterministic :
@@ -60,24 +61,24 @@ def __init__(self,
6061 'image/object/bbox/ymax' :dali .tfrecord .VarLenFeature (dali .tfrecord .float32 , 0.0 )})
6162 if dali_cpu :
6263 self .decode = dali .ops .HostDecoder (device = "cpu" , output_type = dali .types .RGB )
63- self .resize = dali .ops .RandomResizedCrop (
64- device = "cpu" ,
65- size = [height , width ],
66- interp_type = dali .types .INTERP_LINEAR ,
67- random_aspect_ratio = [0.8 , 1.25 ],
68- random_area = [0.1 , 1.0 ],
69- num_attempts = 100 )
64+ resize_device = "cpu"
7065 else :
7166 self .decode = dali .ops .nvJPEGDecoder (
7267 device = "mixed" ,
7368 output_type = dali .types .RGB )
69+ resize_device = "gpu"
70+
71+ if training :
7472 self .resize = dali .ops .RandomResizedCrop (
75- device = "gpu" ,
73+ device = resize_device ,
7674 size = [height , width ],
7775 interp_type = dali .types .INTERP_LINEAR ,
7876 random_aspect_ratio = [0.8 , 1.25 ],
7977 random_area = [0.1 , 1.0 ],
8078 num_attempts = 100 )
79+ else :
80+ # Make sure that every image > 224 for CropMirrorNormalize
81+ self .resize = dali .ops .Resize (device = resize_device , resize_shorter = 256 )
8182
8283 self .normalize = dali .ops .CropMirrorNormalize (
8384 device = "gpu" ,
@@ -117,7 +118,8 @@ def __init__(self,
117118 num_threads ,
118119 dtype = tf .uint8 ,
119120 dali_cpu = True ,
120- deterministic = False ):
121+ deterministic = False ,
122+ training = False ):
121123 pipe = HybridPipe (
122124 tfrec_filenames = filenames ,
123125 tfrec_idx_filenames = idx_filenames ,
@@ -128,7 +130,8 @@ def __init__(self,
128130 device_id = hvd .rank (),
129131 num_gpus = hvd .size (),
130132 deterministic = deterministic ,
131- dali_cpu = dali_cpu )
133+ dali_cpu = dali_cpu ,
134+ training = training )
132135 serialized_pipe = pipe .serialize ()
133136 del pipe
134137
@@ -158,6 +161,7 @@ def image_set(filenames, batch_size, height, width, training=False,
158161 batch_size ,
159162 num_threads ,
160163 dali_cpu = dali_cpu ,
161- deterministic = deterministic )
164+ deterministic = deterministic ,
165+ training = training )
162166 images , labels = preprocessor .get_device_minibatches ()
163167 return (images , labels )
0 commit comments