Reputation: 6035
When using Tensorflow and loading image data I currently have:
image = tf.io.decode_png(tf.io.read_file(path), channels=3)
image = tf.reshape(image, [84, 84, 3])
image = tf.cast(image, tf.float32)
return image / 255.0
But, I want to use tf.per_imdage_standardization
, should I keep the division by 255 or does it become not needed anymore?
Upvotes: 4
Views: 11159
Reputation: 5555
It is not needed anymore. The reason for normalizing the images is to avoid the possibility of exploding gradients because of the high range of the pixels [0, 255]
, and improve the convergence speed. Therefore, you either standardize the each image, so that the range is [-1, 1]
or you just divide the with the maximum pixel value as you are doing, so that the range of the pixels is in the [0, 1]
range.
Another reason why you might want to normalize the image data is if you are using transfer learning. For example, if you are using a pre-trained model that has been trained with images with pixels in the [0, 1]
range, you should make sure that the inputs you are providing the model are in the same range. Otherwise, your results will be messed up.
Upvotes: 13