Skip to content Skip to sidebar Skip to footer

Typeerror: Cannot Handle The Data Type In Pil Image

I have a Pytorch tensor of size (4,3,224,224). When I am trying to convert the first tensor into an Image object, it says: TypeError: Cannot handle this data type I ran the follow

Solution 1:

You are trying to convert 3x224x224 np.array into an image, but PIL.Image expects its images to be of shape 224x224x3, threfore you get an error.
If you transpose your tensor so that the channel dimension will be the last (rather than the first), you should have no problem

img = Image.fromarray(data[0][i].transpose(0,2).numpy().astype(np.uint8))

Post a Comment for "Typeerror: Cannot Handle The Data Type In Pil Image"