0

So when I want to do normalization to float64 in deep learning, I need to make float64_max to be 1 or just every image’s max value as 1?

I read a .nii file to get a 3D array with type float64 and its value is very big. I need to normalize it into 0-1 and float32 type to input my deep learning model. So I was wondering which normalization way is better or correct.

Make float64_max to be 1:

return torch.tensor(img / sys.float_info.max).to(torch.float32)

Make every image's max value as 1:

return torch.nn.functional.normalize(torch.tensor(img)).to(torch.float32)

Also, because the float64 range is much bigger than float32, when I do return torch.tensor(img / sys.float_info.max).to(torch.float32), the value have a chance to be all 0.

PinkR1ver
  • 402
  • 1
  • 4
  • 13

1 Answers1

1

No, you should normalize the max possible value of all images to 1 not the maximum value of each image separately.

For a general image RGB 8-bit image, the maximum value for a pixel channel is 255, so you could divide the entire image's channel value by 255. In this way, you will obtain a new image of type float32 (or float64) with all pixel's channel values in the range [0, 1], but the min is not always 0 and max is not always 1.

cao-nv
  • 184
  • 4
  • Thanks. I think this normalization will be very suitable. To be more clear, the question here is that my dataset is .nii files which are not general RGB 8-bit images and their type is float64. So I think I can divide float64_max like RGB 8-bit image divide 255 to normalize. The question here is that I can not input model with float64 tensor. – PinkR1ver Apr 05 '22 at 12:36
  • https://stackoverflow.com/questions/56741087/how-to-fix-runtimeerror-expected-object-of-scalar-type-float-but-got-scalar-typ I got the answer.Thanks anyway! – PinkR1ver Apr 05 '22 at 13:34