How to test model on a single image
See original GitHub issueHi, How can I test model on new image? what kind of preprocessing I need to pass the image to the network? Is this correct?
image = cv2.imread('test/1.jpg', 1)
draw = image.copy()
draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)
image, scale = resize_image(image)
image = image.astype('float32')
image[:, :, 0] -= 103.939
image[:, :, 1] -= 116.779
image[:, :, 2] -= 123.68
image = image/np.max(image)
start = time.time()
_, _, detections = model.predict_on_batch(np.expand_dims(image, axis=0))
print detections
print("processing time: ", time.time() - start)
predicted_labels = np.argmax(detections[0, :, 4:], axis=1)
scores = detections[0, np.arange(detections.shape[1]), 4 + predicted_labels]
detections[0, :, :4] /= scale
in This case all of my predicted labels are zero. I don’t know it is for bad training or wrong test code.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Testing on a Single Image · Issue #371 - GitHub
I have been using SMP for image segmentation on MRI images of the human brain. I used the UnetPlusPlus model to train and...
Read more >How to test one single image in pytorch - Stack Overflow
I tried to test with batch > 1 and in all cases this works! The architecture: model = models.densenet121(pretrained=True) for param in model....
Read more >How to test single image for a model trained with DataLoader ...
You can use this code for test single image for your model train: import torchvision.transforms as transforms import torchvision.datasets as ...
Read more >How to predict an image using CNN with Keras?
The second is most deep learning models expect a batch of images as input. In this case, we create a batch of one...
Read more >Testing of Image Recognition Model in PyTorch - Javatpoint
Testing of Image Recognition Model in PyTorch ... After seeing this, we will realize that it is the number 5. Now, we will...
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
The only problem is that you don’t need to rescale the values to [0, 1] (in other words, no need for
image = image/np.max(image)
). Other than that it looks fine. I’ll see if I can add an example like this to the jupyter notebook, since it is a more frequent question.Can you let me know if that solves your issue ?
That’s hard to say, it depends on how difficult your dataset is really. But those loss values seem very reasonable to me.
I’ll close this since the original issue was resolved. For further discussions, please join the Slack channel.