How can I get the prediction of a single image?
See original GitHub issueI want just to see the prediction of a single image using the following code:
`
Model reconstruction from JSON file
with open(‘model_struct.json’, ‘r’) as f: model = model_from_json(f.read())
Load weights into the new model
model.load_weights(‘best_weights.h5’)
Load the image file
parser = argparse.ArgumentParser(description=‘Image to test’) parser.add_argument(‘image’, type=str, help=‘The image image file to check’) args = parser.parse_args()
img = load_img(args.image)
Predict
prediction = model.predict(img) `
But it raises the following error:
ValueError: Error when checking : expected input_1 to have 4 dimensions, but got array with shape (720, 960, 3)
Issue Analytics
- State:
- Created 5 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 >Depth prediction from a single image with conditional ...
In this paper, we formulate this problem from single images as a deep adversarial learning framework. A two-stage convolutional network is designed as...
Read more >Depth Map Prediction from a Single Image using a Multi-Scale ...
Predicting depth is an essential component in understanding the 3D geometry of a scene. While for stereo images local correspondence suffices for estimation ......
Read more >Predicting on single image using Fastai Model - Beginner (2018)
You have to pass the image through the transformations before you feed it into the classifier. This was discussed at length here: How...
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 FreeTop 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
Top GitHub Comments
You need to have an additional dimension for batch, even with just one image:
I found the solution for this. I was using utils. load_img() to get image as np.array but in Dronet utils.callback_img() there is extra step before returning image as np array which is
return np.asarray(img, dtype=np.float32) * np.float32(1.0/255.0)
drone_control/dronet/dronet_perception/src/Dronet/utils.py