Created
June 19, 2020 10:37
-
-
Save aliwaqas333/0e31337c2ac80d839b6880f24af18e53 to your computer and use it in GitHub Desktop.
functions to test custom images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def singleImage(path, label= None, show= False): | |
img = cv2.imread(path) | |
assert img is not None,"Immage wasn't read properly" | |
img = cv2.resize(img, (100, 100)) | |
img = torch.from_numpy(img) | |
img = img.permute((2, 0,1)) # model expects image to be of shape [3, 100, 100] | |
img = img.unsqueeze(dim=0).float() # convert single image to batch [1, 3, 100, 100] | |
img = img.to('cuda') # Using the same device as the model | |
pred = model(img) | |
_, preds = torch.max(pred, dim=1) | |
print(classes[preds.item()]) | |
# plt.imshow(img.squeeze(dim=0).permute((1,2,0)).to('cpu')) | |
if show: | |
plt.imshow(cv2.imread(path)) | |
print("the image is :" + classes[preds.item()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment