def distort_image(image):
"""Perform random distortions to the given 4D image and return result"""
# Switch to 3D as that's what these operations require
slices = tf.unpack(image)
output = []
# Perform pixel-wise distortions
for image in slices:
image = tf.image.random_flip_left_right(image)
image = tf.image.random_saturation(image, .2, 2.)
image += tf.truncated_normal(image.get_shape(), stddev=.05)
image = tf.image.random_contrast(image, .85, 1.15)
image = tf.image.random_brightness(image, .3)
output.append(image)
# Go back to 4D
image = tf.pack(output)
return image
评论列表
文章目录