I do not load images directly, as most tutorials show. I load numpy arrays from an hdf5 file that are indeed images itself.
Since I was using Keras, the dimensions order of my numpy arrays are (B,W,H,C). I switched the dimensions W and C, since this is the order PyTorch uses, right (B, C, H, W)?
This is the code I’m using to obtain the PyTorch tensor. I’m totally new to this library and have no idea on how to normalize this PyTorch tensor, whereas all tutorials use the normalize together with other things that are not suitable to my problem.
Thanks!
Edi: Trying to run this code, even without normalization, I faced an error “RuntimeError: Expected object of scalar type Double but got scalar type Float” in the line :
First, thanks for the answer! Second: yes, the error was exactly that, now it’s working with np.dtype(“Float32”). Unfortunately, I cannot use this ImageFolder, I have access only to the hdf5 file with the images in numpy arrays
You can write a simple script to read hdf5 file and write it as files. And then use the Imagefolder.
But also you can call transforms on any torch tensor, their ops are just defined in call.
so for ex - x = torchvision.transforms.Normalize(mean= 0, std= 0.1) x( your tensor)
Thanks! My bad, I did not notice that the input tensor needed to be in (C, H, W) format. Now it’s working, I’m iterating over my X_train tensor to use the normalize function now.