And the .shape of the image is: (250, 350) which I’m not sure how it could have color if it doesn’t have that RGB dimension.
After reading more about this and debugging it, I think the reason this is a weird one is that it is of type PIL.GifImagePlugin.GifImageFile. Now I’m researching how that works, but it looks like PIL may store the colors in some other format for GIF Images
The problem is that GIF Images store everything in a single channel (somehow). To get resize to work correctly here, you need to change it to have a .convert('RGB') so resize will look like this:
def resized_image(fn:Path, sz=128):
x = Image.open(fn).resize((sz,sz)).convert("RGB")
# Convert image to tensor for modeling
return tensor(array(x)).permute(2,0,1).float()/255.
The other way to do it would be by figuring out if it’s a gif type, that would probably save some time doing the convert on every image. I haven’t been able to test this though because my type check doesn’t work like I would expect it to.
This conditional conversion of GIF images solves the problem:
def resized_image(fn:Path, sz=128):
x = Image.open(fn).resize((sz,sz))
x = x.convert('RGB') if x.format=='GIF' else x
# Convert image to tensor for modeling
return tensor(array(x)).permute(2,0,1).float()/255.
Yes, though I think you can do the convert every time, not just when it’s a GIF. The usual PILImage.open does that (unless you use PILImageBW which converts to ‘L’).