Spaces:
Runtime error
Runtime error
Update app.py
#1
by
DHEIVER
- opened
app.py
CHANGED
@@ -59,46 +59,7 @@ class Explainer:
|
|
59 |
fig, _ = viz.visualize_image_attr_multiple(np.transpose(attributions_gs.squeeze().cpu().detach().numpy(), (1,2,0)),
|
60 |
np.transpose(self.transformed_img.squeeze().cpu().detach().numpy(), (1,2,0)),
|
61 |
["original_image", "heat_map"],
|
62 |
-
|
63 |
-
cmap=self.default_cmap,
|
64 |
-
show_colorbar=True)
|
65 |
-
fig.suptitle("SHAP | " + self.fig_title, fontsize=12)
|
66 |
-
return self.convert_fig_to_pil(fig)
|
67 |
-
|
68 |
-
def occlusion(self, stride, sliding_window):
|
69 |
-
occlusion = Occlusion(model)
|
70 |
-
|
71 |
-
attributions_occ = occlusion.attribute(self.input,
|
72 |
-
target=self.pred_label_idx,
|
73 |
-
strides=(3, int(stride), int(stride)),
|
74 |
-
sliding_window_shapes=(3, int(sliding_window), int(sliding_window)),
|
75 |
-
baselines=0)
|
76 |
-
|
77 |
-
fig, _ = viz.visualize_image_attr_multiple(np.transpose(attributions_occ.squeeze().cpu().detach().numpy(), (1,2,0)),
|
78 |
-
np.transpose(self.transformed_img.squeeze().cpu().detach().numpy(), (1,2,0)),
|
79 |
-
["original_image", "heat_map", "heat_map", "masked_image"],
|
80 |
-
["all", "positive", "negative", "positive"],
|
81 |
-
show_colorbar=True,
|
82 |
-
titles=["Original", "Positive Attribution", "Negative Attribution", "Masked"],
|
83 |
-
fig_size=(18, 6)
|
84 |
-
)
|
85 |
-
fig.suptitle("Occlusion | " + self.fig_title, fontsize=12)
|
86 |
-
return self.convert_fig_to_pil(fig)
|
87 |
-
|
88 |
-
def gradcam(self):
|
89 |
-
layer_gradcam = LayerGradCam(self.model, self.model.layer3[1].conv2)
|
90 |
-
attributions_lgc = layer_gradcam.attribute(self.input, target=self.pred_label_idx)
|
91 |
-
|
92 |
-
#_ = viz.visualize_image_attr(attributions_lgc[0].cpu().permute(1,2,0).detach().numpy(),
|
93 |
-
# sign="all",
|
94 |
-
# title="Layer 3 Block 1 Conv 2")
|
95 |
-
upsamp_attr_lgc = LayerAttribution.interpolate(attributions_lgc, self.input.shape[2:])
|
96 |
-
|
97 |
-
fig, _ = viz.visualize_image_attr_multiple(upsamp_attr_lgc[0].cpu().permute(1,2,0).detach().numpy(),
|
98 |
-
self.transformed_img.permute(1,2,0).numpy(),
|
99 |
-
["original_image","blended_heat_map","masked_image"],
|
100 |
-
["all","positive","positive"],
|
101 |
-
show_colorbar=True,
|
102 |
titles=["Original", "Positive Attribution", "Masked"],
|
103 |
fig_size=(18, 6))
|
104 |
fig.suptitle("GradCAM layer3[1].conv2 | " + self.fig_title, fontsize=12)
|
|
|
59 |
fig, _ = viz.visualize_image_attr_multiple(np.transpose(attributions_gs.squeeze().cpu().detach().numpy(), (1,2,0)),
|
60 |
np.transpose(self.transformed_img.squeeze().cpu().detach().numpy(), (1,2,0)),
|
61 |
["original_image", "heat_map"],
|
62 |
+
show_colorbar=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
titles=["Original", "Positive Attribution", "Masked"],
|
64 |
fig_size=(18, 6))
|
65 |
fig.suptitle("GradCAM layer3[1].conv2 | " + self.fig_title, fontsize=12)
|