Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,9 +35,13 @@ def predict(image):
|
|
| 35 |
img = transform(image).unsqueeze(0)
|
| 36 |
with torch.no_grad():
|
| 37 |
outputs = model(img)
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
return class_names[predicted.item()]
|
| 40 |
|
|
|
|
| 41 |
# Save history
|
| 42 |
def save_history(image, result):
|
| 43 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
| 35 |
img = transform(image).unsqueeze(0)
|
| 36 |
with torch.no_grad():
|
| 37 |
outputs = model(img)
|
| 38 |
+
probs = torch.nn.functional.softmax(outputs, dim=1)
|
| 39 |
+
confidence, predicted = torch.max(probs, 1)
|
| 40 |
+
print("Probabilities:", probs.numpy())
|
| 41 |
+
print("Confidence:", confidence.item())
|
| 42 |
return class_names[predicted.item()]
|
| 43 |
|
| 44 |
+
|
| 45 |
# Save history
|
| 46 |
def save_history(image, result):
|
| 47 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|