When attempting to predict a single image I get a "operands could not be broadcast together" error

In working through the lesson 1 stuff I wanted to try using my trained dataset on a separate single test image.

I found several topics on how to do that here, but am getting an error I didnt see mentioned. Here is the code im using:

trn_tfms, val_tfms = tfms_from_model(arch,sz) # get transformations
im = (np.array(Image.open(f’{PATH}testimage1.png’)))
print(im.shape)
im = val_tfms(im)
learn.precompute=False # We’ll pass in a raw image, not activations
preds = learn.predict_array(im[None])
np.argmax(preds) # preds are log probabilities of classes

Note that I broke that up a bit in an effort to understand the error. The same error occurs when condensed into the versions posted on this forum.

Here is the error that occurs on the val_tfms(im) step:

It looks like your image has 4 channels. Is that expected?

Its the same kind of images I am using in my training data. Just one of them I pulled from that actually. Its possible it has 4 by design.

Is a 4th channel an issue for some reason?

turns out that was the case. Not sure why it caused problems but trained fine on the same images. converting everything to jpg seems to have fixed it

Try to use open_image(f’{PATH}testimage1.png’)) instead of Image.open(f’{PATH}testimage1.png’) - this is what fastai uses under the hood.