Learn.predict does not seem to work

Hello,
I am working on a food classifier/detector which predicts if a picture is a hamburger or not. It seems to label everything as a hamburger. I have the following as my code:

!pip install -Uqq fastbook
import fastbook
fastbook.setup_book()



from fastai.vision.all import *
path=untar_data(URLs.FOOD)/'images'/'hamburger'

path.ls()
files=get_image_files(path)
len (files)

files[0]

files[100]

files[0].name



dls = ImageDataLoaders.from_folder(path, valid_pct=0.2,item_tfms=Resize(224))
dls.valid_ds.items[:3]

dls.show_batch()

learn = cnn_learner(dls, resnet34, metrics=error_rate)
learn.fine_tune(1)

learn.predict(files[0])

learn.show_results()

btn_upload = widgets.FileUpload()
btn_upload

img = PILImage.create(btn_upload.data[-1])
img.to_thumb(128,128)

is_burger,_,probs = learn.predict(img)
print(f"Is this a hamburger?: {is_burger}.")

Hey just check dls.vocab and see if there are any classes. Looking at you code I find that you haven’t have any classes to classify like yes or no.

I think the problem with your code is you don’t have a single class and if you are training the model like this. Then you need to create a function to check the probability. So when you take the image and put in learn.predict(img) you get prob and class. As you have only a single class you always get a hamburger. So you need to create a function that checks suppose the probability of the vector is greater than 0.5 then it’s a ham else it isn’t.

Ok thank you for the reply. I will research it.