Spaces:
Sleeping
Sleeping
File size: 609 Bytes
06088b6 296a3ff 06088b6 296a3ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import torch
from PIL import Image
def classify(model, img, trans=None, classes=[], device=torch.device("cpu")):
try:
model = model.eval()
img = img.convert("RGB")
img = trans(img)
img = img.unsqueeze(0)
img = img.to(device)
output = model(img)
_, pred = torch.max(output, 1)
procent = torch.sigmoid(output)
return f"It {classes[pred.item()]} i'm {procent[0][pred[0]]*100:.2f}% sure"
except Exception:
return "Something went wrong😕, please notify the developer with the following message: " + str(Exception) |