Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I still normalize image data (divide by 255) before using per_image_standardization?

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?

like image 969
Kristopher Ives Avatar asked Dec 23 '22 21:12

Kristopher Ives


1 Answers

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.

like image 68
gorjan Avatar answered May 15 '23 14:05

gorjan