signal-grad-cam 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of signal-grad-cam might be problematic. Click here for more details.
- signal_grad_cam/pytorch_cam_builder.py +18 -1
- signal_grad_cam/tensorflow_cam_builder.py +19 -2
- {signal_grad_cam-0.1.1.dist-info → signal_grad_cam-0.1.2.dist-info}/METADATA +1 -1
- signal_grad_cam-0.1.2.dist-info/RECORD +9 -0
- signal_grad_cam-0.1.1.dist-info/RECORD +0 -9
- {signal_grad_cam-0.1.1.dist-info → signal_grad_cam-0.1.2.dist-info}/LICENSE +0 -0
- {signal_grad_cam-0.1.1.dist-info → signal_grad_cam-0.1.2.dist-info}/WHEEL +0 -0
- {signal_grad_cam-0.1.1.dist-info → signal_grad_cam-0.1.2.dist-info}/top_level.txt +0 -0
|
@@ -183,9 +183,26 @@ class TorchCamBuilder(CamBuilder):
|
|
|
183
183
|
# during derivation
|
|
184
184
|
target_scores = torch.log(outputs)
|
|
185
185
|
target_probs = outputs
|
|
186
|
+
|
|
187
|
+
# Adjust results for binary network
|
|
188
|
+
if len(outputs.shape) == 1:
|
|
189
|
+
target_scores = torch.stack([-target_scores, target_scores], dim=1)
|
|
190
|
+
target_probs = torch.stack([1 - target_probs, target_probs], dim=1)
|
|
191
|
+
elif len(outputs.shape) == 2 and outputs.shape[1] == 1:
|
|
192
|
+
target_scores = torch.cat([-target_scores, target_scores], dim=1)
|
|
193
|
+
target_probs = torch.cat([1 - target_probs, target_probs], dim=1)
|
|
186
194
|
else:
|
|
195
|
+
if len(outputs.shape) == 1:
|
|
196
|
+
outputs = torch.stack([-outputs, outputs], dim=1)
|
|
197
|
+
elif len(outputs.shape) == 2 and outputs.shape[1] == 1:
|
|
198
|
+
outputs = torch.cat([-outputs, outputs], dim=1)
|
|
187
199
|
target_scores = outputs
|
|
188
|
-
|
|
200
|
+
|
|
201
|
+
if len(outputs.shape) == 2 and outputs.shape[1] > 1:
|
|
202
|
+
target_probs = torch.softmax(target_scores, dim=1)
|
|
203
|
+
else:
|
|
204
|
+
tmp = torch.sigmoid(target_scores[:, 1])
|
|
205
|
+
target_probs = torch.stack([1 - tmp, tmp], dim=1)
|
|
189
206
|
|
|
190
207
|
target_probs = target_probs[:, target_class].cpu().detach().numpy()
|
|
191
208
|
|
|
@@ -189,7 +189,7 @@ class TfCamBuilder(CamBuilder):
|
|
|
189
189
|
|
|
190
190
|
grad_model = keras.models.Model(self.model.inputs, [target_layer.output, self.model.output])
|
|
191
191
|
extra_inputs_list = extra_inputs_list or []
|
|
192
|
-
with tf.GradientTape() as tape:
|
|
192
|
+
with (tf.GradientTape() as tape):
|
|
193
193
|
self.activations, outputs = grad_model([data_batch] + extra_inputs_list)
|
|
194
194
|
|
|
195
195
|
if softmax_final:
|
|
@@ -197,9 +197,26 @@ class TfCamBuilder(CamBuilder):
|
|
|
197
197
|
# during derivation
|
|
198
198
|
target_scores = tf.math.log(outputs)
|
|
199
199
|
target_probs = outputs
|
|
200
|
+
|
|
201
|
+
# Adjust results for binary network
|
|
202
|
+
if len(outputs.shape) == 1:
|
|
203
|
+
target_scores = tf.stack([-target_scores, target_scores], axis=1)
|
|
204
|
+
target_probs = tf.stack([1 - target_probs, target_probs], axis=1)
|
|
205
|
+
elif len(outputs.shape) == 2 and outputs.shape[1] == 1:
|
|
206
|
+
target_scores = tf.concat([-target_scores, target_scores], axis=1)
|
|
207
|
+
target_probs = tf.concat([1 - target_probs, target_probs], axis=1)
|
|
200
208
|
else:
|
|
209
|
+
if len(outputs.shape) == 1:
|
|
210
|
+
outputs = tf.stack([-outputs, outputs], axis=1)
|
|
211
|
+
elif len(outputs.shape) == 2 and outputs.shape[1] == 1:
|
|
212
|
+
outputs = tf.concat([-outputs, outputs], axis=1)
|
|
201
213
|
target_scores = outputs
|
|
202
|
-
|
|
214
|
+
|
|
215
|
+
if len(outputs.shape) == 2 and outputs.shape[1] > 1:
|
|
216
|
+
target_probs = tf.nn.softmax(target_scores, axis=1)
|
|
217
|
+
else:
|
|
218
|
+
tmp = tf.math.sigmoid(target_scores[:, 1])
|
|
219
|
+
target_probs = tf.stack([1 - tmp, tmp], axis=1)
|
|
203
220
|
|
|
204
221
|
target_scores = target_scores[:, target_class]
|
|
205
222
|
target_probs = target_probs[:, target_class]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: signal-grad-cam
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: SignalGrad-CAM aims at generalising Grad-CAM to one-dimensional applications, while enhancing usability and efficiency.
|
|
5
5
|
Home-page: https://github.com/samuelepe11/signal_grad_cam
|
|
6
6
|
Author: Samuele Pe
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
signal_grad_cam/__init__.py,sha256=JyFFQebs1Rm5r9FCgE68Ii39lLckW8N_gj-nAL5hq2U,137
|
|
2
|
+
signal_grad_cam/cam_builder.py,sha256=KY4o-JMd3ru-TeWQTzmCk4qXTUA7qeAGl1jPbf-tKQY,66588
|
|
3
|
+
signal_grad_cam/pytorch_cam_builder.py,sha256=3nrFEekl8yLwafZcp0I_Kg3QUgeBKGoPQmRAlh4vrJI,17521
|
|
4
|
+
signal_grad_cam/tensorflow_cam_builder.py,sha256=VdFg5h53KzrzboHOmJ8ZaWvJc01Jvy2DdAvvQjtesSg,16904
|
|
5
|
+
signal_grad_cam-0.1.2.dist-info/LICENSE,sha256=pCSaMipV39klP0dlf75SHw5PTl00_cLlS-EiC-LmOkw,1088
|
|
6
|
+
signal_grad_cam-0.1.2.dist-info/METADATA,sha256=_twEITZPMrlZ94ZznndbcWbpaCq8fw6k4k44tJDpelo,10986
|
|
7
|
+
signal_grad_cam-0.1.2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
8
|
+
signal_grad_cam-0.1.2.dist-info/top_level.txt,sha256=S6lf3mfh2uGXJKnUS3qnw6arQu-x3gO8m82WdY7JAIA,16
|
|
9
|
+
signal_grad_cam-0.1.2.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
signal_grad_cam/__init__.py,sha256=JyFFQebs1Rm5r9FCgE68Ii39lLckW8N_gj-nAL5hq2U,137
|
|
2
|
-
signal_grad_cam/cam_builder.py,sha256=KY4o-JMd3ru-TeWQTzmCk4qXTUA7qeAGl1jPbf-tKQY,66588
|
|
3
|
-
signal_grad_cam/pytorch_cam_builder.py,sha256=JPoeTk_fIIg0MtfIA3RuEzNtTcCfaHdzpaSJNwXHCGc,16566
|
|
4
|
-
signal_grad_cam/tensorflow_cam_builder.py,sha256=RCokRq6Q0ZlOphCHXHkRdjcAEy969Jd8vNxtYc6Sq_o,15890
|
|
5
|
-
signal_grad_cam-0.1.1.dist-info/LICENSE,sha256=pCSaMipV39klP0dlf75SHw5PTl00_cLlS-EiC-LmOkw,1088
|
|
6
|
-
signal_grad_cam-0.1.1.dist-info/METADATA,sha256=eZaIXadKb4hoBlZgfRueUNichVHC-YtXGYMpLmZ_0Xo,10986
|
|
7
|
-
signal_grad_cam-0.1.1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
8
|
-
signal_grad_cam-0.1.1.dist-info/top_level.txt,sha256=S6lf3mfh2uGXJKnUS3qnw6arQu-x3gO8m82WdY7JAIA,16
|
|
9
|
-
signal_grad_cam-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|