Update app.py
Browse files
app.py
CHANGED
|
@@ -104,32 +104,31 @@ explanation_text = {
|
|
| 104 |
'Others': "Non-specific features detected, marked as Others."
|
| 105 |
}
|
| 106 |
|
| 107 |
-
# --- Display LIME only
|
| 108 |
def display_lime_visualization(img, true_label, pred_label, pred_idx):
|
| 109 |
-
st.
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
plt.close()
|
| 133 |
|
| 134 |
# --- Streamlit UI ---
|
| 135 |
st.set_page_config(page_title="🧠 Retina Disease Classifier with LIME", layout="centered")
|
|
@@ -153,6 +152,6 @@ if uploaded_file:
|
|
| 153 |
pred_label = CLASS_NAMES[pred_idx]
|
| 154 |
confidence = np.max(preds) * 100
|
| 155 |
|
| 156 |
-
st.success(f"Prediction: **{pred_label}** with confidence {confidence:.2f}%")
|
| 157 |
|
| 158 |
display_lime_visualization(processed_img, "Uploaded Image", pred_label, pred_idx)
|
|
|
|
| 104 |
'Others': "Non-specific features detected, marked as Others."
|
| 105 |
}
|
| 106 |
|
| 107 |
+
# --- Display LIME only ---
|
| 108 |
def display_lime_visualization(img, true_label, pred_label, pred_idx):
|
| 109 |
+
with st.spinner("🟡 LIME Explanation is Loading..."):
|
| 110 |
+
explanation = explainer.explain_instance(
|
| 111 |
+
image=img,
|
| 112 |
+
classifier_fn=predict_fn,
|
| 113 |
+
top_labels=1,
|
| 114 |
+
hide_color=0,
|
| 115 |
+
num_samples=1000
|
| 116 |
+
)
|
| 117 |
+
temp, mask = explanation.get_image_and_mask(label=pred_idx, positive_only=True, num_features=10, hide_rest=False)
|
| 118 |
+
|
| 119 |
+
fig, axs = plt.subplots(1, 2, figsize=(12, 5))
|
| 120 |
+
axs[0].imshow(img)
|
| 121 |
+
axs[0].set_title(f"Original\nTrue: {true_label}")
|
| 122 |
+
axs[1].imshow(mark_boundaries(temp, mask))
|
| 123 |
+
axs[1].set_title(f"LIME Explanation\nPred: {pred_label}")
|
| 124 |
+
for ax in axs:
|
| 125 |
+
ax.axis('off')
|
| 126 |
+
|
| 127 |
+
summary = explanation_text.get(pred_label, "Model detected features matching this class.")
|
| 128 |
+
plt.figtext(0.5, 0.01, summary, wrap=True, ha='center', fontsize=10)
|
| 129 |
+
plt.tight_layout(rect=[0, 0.03, 1, 1])
|
| 130 |
+
st.pyplot(fig)
|
| 131 |
+
plt.close()
|
|
|
|
| 132 |
|
| 133 |
# --- Streamlit UI ---
|
| 134 |
st.set_page_config(page_title="🧠 Retina Disease Classifier with LIME", layout="centered")
|
|
|
|
| 152 |
pred_label = CLASS_NAMES[pred_idx]
|
| 153 |
confidence = np.max(preds) * 100
|
| 154 |
|
| 155 |
+
st.success(f"✅ Prediction: **{pred_label}** with confidence **{confidence:.2f}%**")
|
| 156 |
|
| 157 |
display_lime_visualization(processed_img, "Uploaded Image", pred_label, pred_idx)
|