简体   繁体   English

Tensorflow 2.0 CNN训练:图像增强功能将像素值移到[0,1]范围之外。 这有问题吗?

[英]Tensorflow 2.0 CNN training: Image augmentation function shifts pixel values outside of the [0, 1] range. Is this a problem?

I am working on my specific data augmentation function to train a CNN in TensorFlow 2.0 . 我正在使用我的特定数据增强功能来训练TensorFlow 2.0中CNN The image data I'm using are stored in a numpy multidimensional RGB array; 我使用的图像数据存储在numpy多维RGB数组中; all its pixel values are floats in the [0, 1] range. 其所有像素值均为[0,1]范围内的浮点数。

While playing with function tensorflow.image.random_brightness ( documentation ) I found that its pixel values are shifted outside of the [0, 1] range (etiher above or below). 在使用tensorflow.image.random_brightness函数( 文档 )时,我发现其像素值移到[0,1]范围之外(无论在上方还是下方)。 When I try to visualise them using matplotlib.pyplot.imshow() I get the following message: 当我尝试使用matplotlib.pyplot.imshow()可视化它们时,收到以下消息:

Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). 使用RGB数据将输入数据剪切到有效显示范围(对于浮点数为[0..1],对于整数为[0..255])。

I also found that when I try to re-normalize the data in that range, the image comes back to its original look (making the whole process useless). 我还发现,当我尝试在该范围内对数据进行规范化时,图像会恢复其原始外观(使整个过程变得无用)。

Are pixel values outside of the [0, 1] range a problem for CNN training? CNN训练是否超出[0,1]范围的像素值成为问题? And if this represents a problem, what can I do to have pixel values in the correct range, without giving up adjusting brightness? 如果这代表问题,我该怎么做才能在不放弃调节亮度的情况下将像素值保持在正确的范围内?

Yes it is a problem since your representing in 0-1 something that is in 0-255, therefore when you feed a value greater than 1. to your CNN, you are feeding the CNN something that it will never see in a real scenario. 是的,这是一个问题,因为您用0-1表示0-255中的某物,因此,当您向CNN馈入大于1的值时,您正在馈给CNN某种在实际情况下永远不会看到的东西。

Applying random brightness is OK, but you should take care of the overflow problems using the tf.clip_by_value function: 可以应用随机亮度,但是您应该使用tf.clip_by_value函数来解决溢出问题:

image = tf.clip_by_value(image, clip_value_min=0., clip_value_max=1.)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM