10
10
""" Implementation of AblationCAM
11
11
https://openaccess.thecvf.com/content_WACV_2020/papers/Desai_Ablation-CAM_Visual_Explanations_for_Deep_Convolutional_Network_via_Gradient-free_Localization_WACV_2020_paper.pdf
12
12
13
- Ablate individual activations, and then measure the drop in the target score .
13
+ Ablate individual activations, and then measure the drop in the target scores .
14
14
15
15
In the current implementation, the target layer activations is cached, so it won't be re-computed.
16
16
However layers before it, if any, will not be cached.
@@ -88,8 +88,8 @@ def get_cam_weights(self,
88
88
[target (output ).cpu ().item () for target , output in zip (targets , outputs )])
89
89
90
90
# Replace the layer with the ablation layer.
91
- # When we finish, we will replace it back, so the original model is
92
- # unchanged.
91
+ # When we finish, we will replace it back, so the
92
+ # original model is unchanged.
93
93
ablation_layer = self .ablation_layer
94
94
replace_layer_recursive (self .model , target_layer , ablation_layer )
95
95
@@ -122,9 +122,9 @@ def get_cam_weights(self,
122
122
# Change the state of the ablation layer so it ablates the next channels.
123
123
# TBD: Move this into the ablation layer forward pass.
124
124
ablation_layer .set_next_batch (
125
- input_batch_index = batch_index ,
126
- activations = self .activations ,
127
- num_channels_to_ablate = batch_tensor .size (0 ))
125
+ input_batch_index = batch_index ,
126
+ activations = self .activations ,
127
+ num_channels_to_ablate = batch_tensor .size (0 ))
128
128
score = [target (o ).cpu ().item ()
129
129
for o in self .model (batch_tensor )]
130
130
new_scores .extend (score )
@@ -145,4 +145,5 @@ def get_cam_weights(self,
145
145
146
146
# Replace the model back to the original state
147
147
replace_layer_recursive (self .model , ablation_layer , target_layer )
148
+ # Returning the weights from new_scores
148
149
return weights
0 commit comments