question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to predict on one image?

See original GitHub issue

Hello,

I’m still trying to reproduce this example using Keras.

I was able to train the model, but I have problems with predicting. I want to see a prediction for a one single image. Here’s my code:

    model.load_weights("camvid_model.h5")
    test_image = cv2.imread("Seq05VD_f01980.png") # It's an image from test folder of CamVid dataset
    ready_image = np.expand_dims(test_image, axis=0).astype('float')
    predicted_image = model.predict(ready_image)[0, :, :, :]
    predicted_image = (predicted_image * 255).astype(np.uint8)
    cv2.imwrite(f"prediction.jpg", predicted_image)

Here’s a test image (there’s a car in the center): Seq05VD_f01980

Here’s my prediction for the test image: prediction

As you can see, my prediction is just a monochrome mess, not a car shape in the center. Are there any mistakes in my prediction code?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
JordanMakesMapscommented, May 26, 2020

@EtagiBI, nope, nor should it be used with the validation (just training). For validation and testing, just the pre-processing should be applied.

There is such as a thing called Test-Time Augmentation (TTA) which you might want to look into later down the road. It helps to provide slightly higher testing scores.

1reaction
JordanMakesMapscommented, May 25, 2020

It doesn’t look like you included the preprocess_input function in the prediction phase. The images you feed to the model during the prediction phase need to follow the exact same format that the images underwent during the training phase.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keras: model.predict for a single image - Stack Overflow
I'd like to make a prediction for a single image with Keras. I've trained my model so I'm just loading the weights.
Read more >
How to predict an image using CNN with Keras?
How to predict an image's type? · Load an image. · Resize it to a predefined size such as 224 x 224 pixels....
Read more >
Prediction for one image in keras - Part 1 (2017) - Fast.ai forums
function is used for predicting the images in the test set. Compile your model. Fit your model.
Read more >
how to predict an image using saved model
Having problems with dimensions is very common. As others have mentioned, the method predict expects to get a batch of images.
Read more >
How to predict with just one image in keras? - Kaggle
How to predict with just one image in keras? ... I trained my model with 50 images samples in TF Keras, how can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found