Last active
January 14, 2021 15:51
-
-
Save johschmidt42/ff0f87965d15a62e5a3d748cf7fb78e7 to your computer and use it in GitHub Desktop.
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
import torch | |
def predict(img, | |
model, | |
preprocess, | |
postprocess, | |
device, | |
): | |
model.eval() | |
img = preprocess(img) # preprocess image | |
x = torch.from_numpy(img).to(device) # to torch, send to device | |
with torch.no_grad(): | |
out = model(x) # send through model/network | |
out_softmax = torch.softmax(out, dim=1) # perform softmax on outputs | |
result = postprocess(out_softmax) # postprocess outputs | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment