pytorch-grad-cam
pytorch-grad-cam copied to clipboard
Swin Transformer cannot cam-->grad can be implicitly created only for scalar outputs
File "/home/xxx/Project/latested/camvisual.py", line 227, in
Issue Resolved
If you are using the Swin Transformer, you may need to modify or add the following code: Please add this code at the end.
def forward():
...
outputs = self.activations_and_grads(input_tensor)
# add this way
out_nor = self.model.norm(outputs)
out_poll = torch.flatten(self.model.avgpool(out_nor.transpose(1, 2)), 1)
outputs = self.model.head(out_poll)
Thank you for sharing the code, It is important not to ignore the output that hasn't been flattened