Skip to content

Commit 9699238

Browse files
authored
Merge pull request #486 from tensorlayer/update-dataset-example
Update dataset example
2 parents 8052c75 + d628eec commit 9699238

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

example/tutorial_tf_dataset_voc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def _data_aug_fn(im, ann):
4141
ann = ann.decode()
4242
ann = tl.prepro.parse_darknet_ann_str_to_list(ann)
4343
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)
4646
# im = tl.prepro.illumination(im, gamma=(0.5, 1.5),
4747
# contrast=(0.5, 1.5), saturation=(0.5, 1.5), is_random=True) # TypeError: Cannot handle this data type
4848
## random horizontal flip
@@ -65,7 +65,12 @@ def _map_fn(filename, annotation):
6565
image = tf.read_file(filename)
6666
image = tf.image.decode_jpeg(image, channels=3)
6767
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
6974
image, annotation = tf.py_func(_data_aug_fn, [image, annotation], [tf.float32, tf.string])
7075
return image, annotation
7176

0 commit comments

Comments
 (0)