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 test model on a single image

See original GitHub issue

Hi, 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hgaisercommented, Jan 15, 2018

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 ?

0reactions
hgaisercommented, Jan 18, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

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