Rescale integer should be 255. or 255 in data augmentation assignment

Hello,

As in week 1, for training data, I used rescale of 1.0/255.

but in week 2, the instructor explains in one of the videos to use rescale as 1.0/255

So want to know what would be the right fit for this, and how and why it may vary with this change.

Thank you
DP

Hello @Deepti_Prasad ,

In C2W2 also you need to use rescale=1./255

With regards,
Nilosree Sengupta

hey in C2W1 I used rescale=1./255.
and I cleared the model with accuracy.

So why do I need to use rescale=1./255 (I mean how does placing or not placing integer to 255 make difference in training the model as I can see no difference in this assignment cell too for week 2)

Hello @Deepti_Prasad ,

Could you kindly clear what is your doubt?

  1. Why we use 255 and not any other value?
  2. should you use 255. or 255?

With regards,
Nilosree Sengupta

It doesn’t make a difference, because of the type coercion rules in python. If any element of an expression is a floating point value, then all the values will be coerced to float.

The place where you might get in trouble is if you say this:

m = 5
x = 1 / m

In python 2.x, the computation will be done in integer arithmetic and the answer will be 0 as an integer.

But they changed the rules in python 3.x, so that you get 0.2.

2 Likes

2nd question 255 or 255.

I checked now with 255. my model training didn’t gave an accuracy of 80%

So I am trying now with 255

And you should get exactly the same answer for the reason I just gave.

1 Like

hmmm so the accuracy issue in my model must be not related rescale 255 :frowning:

ok I will check, where I need to work on. Thank you Paul. I understood the integer reference you gave but when I remember when I was doing a course in deep learning.ai, the integer made a difference in a test code. So wanted to confirm this part. Thanks again

Regards
DP

Here value 255 in the expression "rescale=1./255" is the normalization factor which is used to scale down the pixel values .

We use 255 because it goes with the maximum pixel intensity value in an 8-bit image representation.

Yeah @paulinpaloalto Sir has rightly said

There used to be cases in TensorFlow where the type coercion rules were less permissive than they are in general python. In the Art Generation exercise in DLS C4, there used to be some landmines you could step on, but those have also been fixed now analogous to the python 2.x to 3.x change I showed above.

yes this part I did understand from the video. Hey your answer got me to ask one more doubt. So the rescaling will depend on the image bit representation. what if there is variation in bit in training image representation and validation image representation, does that still have an effect on rescale?

Actually we all are active altogether, and posting answers altogether, I read your response later.
This part :

The above was for why 255 and not other value.

You can use other values as well, but 255 is the generally used one.

This was not for why 255. or 255

1 Like

this is the answer for your question @Deepti_Prasad .