AlexOlsen / DeepWeeds

A Multiclass Weed Species Image Dataset for Deep Learning
https://www.nature.com/articles/s41598-018-38343-3
Apache License 2.0
199 stars 85 forks source link

Inference on single images #8

Open diana-xie opened 4 years ago

diana-xie commented 4 years ago

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 commented 4 years ago

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

erinmgraham commented 3 years ago

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 commented 3 years ago

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

erinmgraham commented 3 years ago

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 commented 3 years ago

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.