Skip to content

How to test on custom images at run time? #74

Answered by ashmalvayani
ashmalvayani asked this question in Q&A
Discussion options

You must be logged in to vote

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: {…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@ashmalvayani
Comment options

@SkalskiP
Comment options

@ashmalvayani
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ashmalvayani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request
2 participants
Converted from issue

This discussion was converted from issue #73 on February 24, 2023 11:12.