【发布时间】:2018-06-09 22:49:28
【问题描述】:
'我正在 TensorFlow 中尝试使用旋转、随机亮度、随机饱和度等各种方法来增强图像数据。我观察到 tf.image.random_brightness 的输出并不一致 - 有时它会产生负值。我理解随机性,但产生负值是否正确?当我尝试使用 matplotlib.pyplot 绘制图像时,它失败说 ValueError: Floating point image RGB values must be in the 0..1 range 下面是一些代码示例:'
# 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 is returned to aug_train_images
print (aug_train_images[i])
'Some sample output:'
[[[-0.18852733 -0.27872342 -0.31009597]
[-0.18059228 -0.2786315 -0.3060825 ]
[-0.1765788 -0.27461803 -0.302069 ]
...
[-0.20366213 -0.19974056 -0.18405429]
[-0.22792684 -0.22437292 -0.20458125]
[-0.24324547 -0.23166458 -0.21205674]]
'我在 Ubuntu 16.10 上使用带有 Python 3.5.3 和 TensorFlow CPU 版本 1.5.0-rc0 的 Jupyter notebook。'
【问题讨论】:
-
keras 已经内置了图像数据增强功能。为什么不使用它?
-
感谢米奇的建议。现在我正在学习 TensorFlow 和深度学习,因此试图将我的代码限制为 TF API。我觉得使用高级 API 会更容易并且会产生良好的结果,但学习(即我学习深度学习!)会更少。
-
另外,我在 Keras 的数据增强库中找不到更改亮度/饱和度的方法。
-
但是改变亮度/饱和度实际上会给卷积网络提供更多信息吗?我怀疑不是。
标签: python tensorflow