0

I am working on my specific data augmentation function to train a CNN in TensorFlow 2.0. The image data I'm using are stored in a numpy multidimensional RGB array; all its pixel values are floats in the [0, 1] range.

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). When I try to visualise them using matplotlib.pyplot.imshow() I get the following message:

Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).

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? And if this represents a problem, what can I do to have pixel values in the correct range, without giving up adjusting brightness?

Leevo
  • 1,683
  • 2
  • 17
  • 34

1 Answers1

2

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.

Applying random brightness is OK, but you should take care of the overflow problems using the tf.clip_by_value function:

image = tf.clip_by_value(image, clip_value_min=0., clip_value_max=1.)
nessuno
  • 26,493
  • 5
  • 83
  • 74
  • Do you suggest to put everything in the [0, 255] before using `tf.clip_by_value`? Or is [0, 1] fine? – Leevo Apr 23 '19 at 10:48
  • 1
    Convert the image to float first (values in [0,1]), then apply random brightness + clip in [0,1] – nessuno Apr 23 '19 at 11:41