How to use Learner.predict (list index out of range)

Hello,

I’ve recently started fast.ai and was successful in creating a model for a dataset that consisted of single-channel images (by stacking channels, converting them to 3-channel, and storing them). I was successful in creating the model, saving it and exporting it. My major problem is I cannot seem to understand what needs to go into the learner.predict() function:

My code:

The full notebook link is as follows: https://www.kaggle.com/namansood/fastai-image-channel

Thank you very much for your time

@DonutPancakes welcome to Fast.ai !!!

the issue seems to be with what you are passing to the predict function. You will want to feed the model tensor(s) or image as opposed to a file name. So try something like:

img = Image.open(’/data/train/1/1806.jpg’) and then feed that object into the predict function

Hope that helps!!

It didn’t work, this was the error that followed it

AssertionError: Expected an input of type in

  • <class ‘pathlib.PosixPath’>
  • <class ‘pathlib.Path’>
  • <class ‘str’>
  • <class ‘torch.Tensor’>
  • <class ‘numpy.ndarray’>
  • <class ‘bytes’>
  • <class ‘fastai.vision.core.PILImage’>
    but got <class ‘PIL.JpegImagePlugin.JpegImageFile’>

I also tried using PILImage.create() and encountered the following error

The notebook link is: https://www.kaggle.com/namansood/fastai-image-channel

Was there ever a solution? I’m running into the same problem