How to test on custom images at run time? #74
-
Search before asking
DescriptionThe evaluation code block in your notebook reads the valid_ds and use iterators to extract inputs and labels to predict the classes further. I want to test my model on run time for which I do not have any labels. For eg: I have 5 images of digits 1, 2, 3, 4, 5 respectively (I know labels because I can see them, no written csv label files). How will I do that? AdditionalNo response Are you willing to submit a PR?
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
👋 Hello @ashmalvayani, thank you for leaving an issue on Roboflow Notebooks. 🐞 Bug reportsIf you are filing a bug report, please be as detailed as possible. This will help us more easily diagnose and resolve the problem you are facing. To learn more about contributing, check out our Contributing Guidelines. If you require support with custom code that is not part of Roboflow Notebooks, please reach out on the Roboflow Forum or on the GitHub Discussions page associated with this repository. 💬 Get in touchDo you have more questions about Roboflow that we haven't responded to yet? Feel free to ask them on the Roboflow Discuss forum. Our developer advocates and community team actively respond to questions there. To ask questions about Notebooks, head over to the GitHub Discussions section of this repository. |
Beta Was this translation helpful? Give feedback.
-
Hi, @ashmalvayani 👋🏻! LEt me first move that conversation to our QA section. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure which notebook we are talking about, but in general:
|
Beta Was this translation helpful? Give feedback.
-
Here's the code for the problem I asked. SOLVED. #working perfectly for a single image testing h,w,c = img.shape with torch.no_grad(): originalInput = inputs inputs = torch.tensor(np.stack(feature_extractor(inputs)['pixel_values'], axis=0)) prediction, loss = model(inputs) predicted_class = np.argmax(prediction.cpu()) |
Beta Was this translation helpful? Give feedback.
Here's the code for the problem I asked. SOLVED.
#working perfectly for a single image testing
image_path = '/content/1.PNG'
img = cv2.imread(image_path)
h,w,c = img.shape
img = np.transpose(img, (2, 0, 1))
img = np.expand_dims(img,axis=0)
with torch.no_grad():
inputs = torch.from_numpy(img)
inputs = inputs[0].permute(1, 2, 0)
originalInput = inputs
for index, array in enumerate(inputs):
inputs[index] = np.squeeze(array)
inputs = torch.tensor(np.stack(feature_extractor(inputs)['pixel_values'], axis=0))
inputs = inputs.to(device)
prediction, loss = model(inputs)
predicted_class = np.argmax(prediction.cpu())
plt.imshow(originalInput)
plt.xlim(224,0)
plt.ylim(224,0)
plt.title(f'Prediction: {…