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:
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
you should use a fastai version loss function to avoid these errors,in your case when you creating the learner replace F.crossentropy with loss_func=CrossEntropyLossFlat(),dont forget the parenthesis.
Furthermore you should pass a PILImage data to the predict() method,one approach to create one is:
img = PILImage.create(filename)
or use a upload widge:
from fastai.vision.widgets import *
btn_upload = widgets.FileUpload()
btn_upload
img = PILImage.create(btn_upload.data[-1])
then you can pass img to the learn_inf.predict():
learn_inf.predict(img)