@@ -41,8 +41,8 @@ def _data_aug_fn(im, ann):
41
41
ann = ann .decode ()
42
42
ann = tl .prepro .parse_darknet_ann_str_to_list (ann )
43
43
clas , coords = tl .prepro .parse_darknet_ann_list_to_cls_box (ann )
44
- ## random brightness, contrast and saturation
45
- im = tl .prepro .brightness (im , gamma = 0.5 , gain = 1 , is_random = True )
44
+ ## random brightness, contrast and saturation (tf.image API is faster)
45
+ # im = tl.prepro.brightness(im, gamma=0.5, gain=1, is_random=True)
46
46
# im = tl.prepro.illumination(im, gamma=(0.5, 1.5),
47
47
# contrast=(0.5, 1.5), saturation=(0.5, 1.5), is_random=True) # TypeError: Cannot handle this data type
48
48
## random horizontal flip
@@ -65,7 +65,12 @@ def _map_fn(filename, annotation):
65
65
image = tf .read_file (filename )
66
66
image = tf .image .decode_jpeg (image , channels = 3 )
67
67
image = tf .image .convert_image_dtype (image , dtype = tf .float32 )
68
- ## data augmentation
68
+ ## data augmentation for image only 0.02s
69
+ image = tf .image .random_brightness (image , max_delta = 63 )
70
+ image = tf .image .random_contrast (image , lower = 0.2 , upper = 1.8 )
71
+ # subtract off the mean and divide by the variance of the pixels. (optional)
72
+ # img = tf.image.per_image_standardization(img)
73
+ ## data augmentation for image and bounding box
69
74
image , annotation = tf .py_func (_data_aug_fn , [image , annotation ], [tf .float32 , tf .string ])
70
75
return image , annotation
71
76
0 commit comments