``我正在尝试使用TensorFlow中的图像数据增强方法,例如旋转,随机亮度,随机饱和度等各种方法。我观察到的是tf.image.random_brightness的输出不一致-有时会产生负值。我了解随机性,但是产生负值是否正确?当我尝试使用matplotlib.pyplot绘制图像时,它无法显示ValueError:浮点图像RGB值必须在0..1范围内。下面是一些代码示例:'
# Function which reads file and converts to image array
def read_images_from_file (input_queue):
label = input_queue[1]
file_content = tf.read_file(input_queue[0])
image = tf.image.decode_jpeg(file_content, channels=NUM_CHANNELS)
image = tf.image.convert_image_dtype(image, dtype=tf.float32, saturate=True)
image = tf.image.resize_images(image, [IMAGE_HEIGHT, IMAGE_WIDTH])
.....
#inside a function which applies various augmentations - code shown only for brightness
X_init = tf.placeholder(tf.float32, shape=images.shape)
X = tf.Variable(X_init)
sess.run(tf.variables_initializer([X]), feed_dict={X_init: images})
aug_images, aug_labels = (sess.run(tf.map_fn(lambda params: (tf.image.random_brightness(params[0], 0.8, 1), params[1]), (X, labels))))
#inside a loop after calling above function - output of function …Run Code Online (Sandbox Code Playgroud)