DeepWeeds icon indicating copy to clipboard operation
DeepWeeds copied to clipboard

Inference on single images

Open diana-xie opened this issue 4 years ago • 5 comments

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!

diana-xie avatar May 06 '20 23:05 diana-xie

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

AsadSeeker avatar Jul 24 '20 14:07 AsadSeeker

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

erinmgraham avatar Jan 14 '21 05:01 erinmgraham

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

diana-xie avatar Jan 15 '21 01:01 diana-xie

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

erinmgraham avatar Jan 21 '21 04:01 erinmgraham

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.

hami-sh avatar Aug 03 '21 02:08 hami-sh