Update app.py
Browse files
app.py
CHANGED
|
@@ -22,6 +22,24 @@ if uploaded_file:
|
|
| 22 |
|
| 23 |
probs = predict(model, img_tensor, device)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
st.subheader("Predictions")
|
| 26 |
for disease, prob in probs.items():
|
| 27 |
st.write(f"**{disease}**: {prob:.4f}")
|
|
|
|
| 22 |
|
| 23 |
probs = predict(model, img_tensor, device)
|
| 24 |
|
| 25 |
+
# Get top class
|
| 26 |
+
top_disease = max(probs, key=probs.get)
|
| 27 |
+
target_idx = list(probs.keys()).index(top_disease)
|
| 28 |
+
|
| 29 |
+
# Grad-CAM
|
| 30 |
+
cam = generate_gradcam(model, img_tensor, target_idx, device)
|
| 31 |
+
|
| 32 |
+
# Overlay on image
|
| 33 |
+
image_resized = image.resize((224, 224))
|
| 34 |
+
img_np = np.array(image_resized)
|
| 35 |
+
heatmap = cv2.applyColorMap(np.uint8(255 * cam), cv2.COLORMAP_JET)
|
| 36 |
+
overlay = cv2.addWeighted(img_np, 0.6, heatmap, 0.4, 0)
|
| 37 |
+
|
| 38 |
+
# Show it
|
| 39 |
+
st.subheader(f"Grad-CAM Visualization: {top_disease}")
|
| 40 |
+
st.image(overlay, use_column_width=True)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
st.subheader("Predictions")
|
| 44 |
for disease, prob in probs.items():
|
| 45 |
st.write(f"**{disease}**: {prob:.4f}")
|