@@ -92,8 +92,19 @@ def cvt_gray(
92
92
"""
93
93
img = Image .fromarray (sample_input .images .numpy ())
94
94
if random .uniform (0 , 1 ) < probability :
95
+ new_img = Image .new (
96
+ img .mode ,
97
+ (
98
+ img .size [0 ],
99
+ img .size [1 ],
100
+ ),
101
+ (0 , 0 , 0 ),
102
+ )
95
103
img = ImageOps .grayscale (img )
96
- sample_output .images .append (img )
104
+ new_img .paste (img , (0 , 0 ))
105
+ sample_output .images .append (new_img )
106
+ else :
107
+ sample_output .images .append (img )
97
108
sample_output .labels .append (sample_input .labels .numpy ())
98
109
return sample_output
99
110
@@ -158,7 +169,7 @@ def cvt_crop(
158
169
Args:
159
170
sample_input: input dataset passed to generate output dataset.
160
171
sample_output: output dataset which will contain transforms of input dataset.
161
- crop_locations: tuple (start_x,start_y,end_x,end_y) to determine region for crop. Defaults to -1 which causes a centre crop.
172
+ crop_locations: tuple (start_x,start_y,end_x,end_y) to determine region for crop. Defaults to None which causes a centre crop.
162
173
probability: probability to randomly apply transformation. Defaults to 0.5.
163
174
164
175
Returns:
@@ -191,7 +202,7 @@ def cvt_resize(
191
202
Args:
192
203
sample_input: input dataset passed to generate output dataset.
193
204
sample_output: output dataset which will contain transforms of input dataset.
194
- resize_size: tuple (width,height) to determine dimensions for resize. Defaults to -1 which prevents resizing.
205
+ resize_size: tuple (width,height) to determine dimensions for resize. Defaults to None which prevents resizing.
195
206
probability: probability to randomly apply transformation. Defaults to 0.5.
196
207
197
208
Returns:
@@ -298,7 +309,9 @@ def cvt_padding(
298
309
pad_color ,
299
310
)
300
311
new_img .paste (img , (pad_size [0 ], pad_size [1 ]))
301
- sample_output .images .append (new_img )
312
+ sample_output .images .append (new_img )
313
+ else :
314
+ sample_output .images .append (img )
302
315
sample_output .labels .append (sample_input .labels .numpy ())
303
316
return sample_output
304
317
@@ -325,13 +338,15 @@ def cvt_padding(
325
338
args = parser .parse_args ()
326
339
327
340
ds_input = hub .load (args .input_path )
328
- ds_output = hub .like (args .output_path , ds_input )
341
+ ds_output = hub .like (args .output_path , ds_input , overwrite = True )
329
342
pipeline = hub .compose (
330
343
[
331
- cvt_horizontal_flip (probability = 0.4 ),
344
+ cvt_horizontal_flip (probability = 0.5 ),
332
345
cvt_crop (probability = 0.8 ),
333
346
cvt_gray (probability = 0.7 ),
334
- cvt_padding (pad_size = (10 , 10 , 10 , 10 ), bg_color = (0 , 0 , 0 ), probability = 0.5 ),
347
+ cvt_padding (
348
+ pad_size = (10 , 10 , 10 , 10 ), pad_color = (0 , 0 , 0 ), probability = 0.4
349
+ ),
335
350
cvt_resize (resize_size = (100 , 80 ), probability = 0.6 ),
336
351
]
337
352
)
0 commit comments