How to predict on one image?
See original GitHub issueHello,
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):
Here’s my prediction for the test image:
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:
- Created 3 years ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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.