Data loader tensor duplicating image 9x

I am looking at what tensor data is being passed into the model. I expected a resized image however I am seeing the data being duplicated 9 times in the same down sampled image. This is on the PETs data set. I get the same results on Windows and linux. is this an error or am I missing something?


The erroneous result stems from how you are converting your channels-first array into a channels-last one. Specifically, NumPy and PyTorch would yield an incorrect output if you attempt swapping axes through reshaping. Instead, you must use numpy.transpose or torch.permute; for instance, in your case, you would do,

im_arr = np.transpose(im_arr, axes=(1, 2, 0))

You can refer to the documentation for more information.

Please let me know if you have other issues.


Thanks! It is now showing the image as I expected. You are a lifesaver.

1 Like