Skip to content

Instantly share code, notes, and snippets.

@johschmidt42
Last active January 14, 2021 15:51
Show Gist options
  • Save johschmidt42/ff0f87965d15a62e5a3d748cf7fb78e7 to your computer and use it in GitHub Desktop.
Save johschmidt42/ff0f87965d15a62e5a3d748cf7fb78e7 to your computer and use it in GitHub Desktop.
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