Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference on single images #8

Open
diana-xie opened this issue May 6, 2020 · 5 comments
Open

Inference on single images #8

diana-xie opened this issue May 6, 2020 · 5 comments

Comments

@diana-xie
Copy link

Hi Alex, thanks so much for sharing the code! I am new to deep learning and found your commented code very helpful and clear.

I am attempting to run inference on single images from your study, using one of your pre-trained models. I think I’m running into some issues though. I downloaded the ResNet-50 model (resnet.hdf5) and loaded it to make predictions on single images at a time (using deepweeds.inference() ). However all the predictions are for the Negative class, since this probability is always much higher than the remaining classes.

Also tried running model.predict_generator() (from deepweeds.cross_validate() ) on just a test subset of data (‘test_subset0.csv’), to see if the predictions turned out differently. This was done on a Google Colab notebook with GPU, but it seems to be hanging and not completing with both ~3500 images and ~10 images (to see if runtime was the issue).

Do you know what I might be doing wrong?

Thanks!

@AsadSeeker
Copy link

hay @diana-xie ... did you find solution to your problem ? actually i also want to infer on single image ....

@erinmgraham
Copy link

Hi @diana-xie, I'm having the same issue you were having with all predictions for the Negative class. Did you find a solution? To troubleshoot, I modified inference(model) to add a column for the predicted class to the 'tf_inference_times.csv' output:
pred_class = [] # before the for loop on line 309
pred_class.append(y_pred) # after line 324
writer.writerow(['Filename', 'Preprocessing time (ms)', 'Inference time (ms)', 'Predicted Class']) # line 333
for i in range(image_count):
writer.writerow([filenames[i], preprocessing_times[i] * 1000, inference_times[i] * 1000, pred_class[i]]) # line 335
I could then use 'python deepweeds.py inference --model models/resnet.hdf5' to see the predictions quickly.
This also meant I could get a single prediction by making sure the image is in the 'images' folder and replacing all the image rows in 'labels.csv' with a single row just for that image. HTH

@diana-xie
Copy link
Author

Oh cool! No, I haven't found a solution yet. This is super helpful - thank you for posting.

@erinmgraham
Copy link

Hi @diana-xie, I think I found a solution. In the inference definition, can you change line 314 from img = resize(img, (224, 224)) to img = crop(img, (224, 224)) and check that it works for you? Thanks, Erin

@hami-sh
Copy link

hami-sh commented Aug 3, 2021

That worked for me @erinmgraham ! Thanks very much :D
Working on a fork that will fix a few issues and includes an updated requirements.txt. Will post back soon.

EDIT: #10 Alright view this PR for a fix! Hopefully gets merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@erinmgraham @AsadSeeker @diana-xie @hami-sh and others