Closed wyli closed 1 year ago
Hello 👋 I'd like a go at it if no one else is working on this 🤗
sure, please go ahead, let me know if you need any help
Finally got some time to work on this. Not sure if I've mistaken the intent here, but I'm not able to reproduce the issue. For a binary classifier, I'm setting the out_channels=1
below and everything seems to work.
from monai.networks.nets import DenseNet121
from monai.visualize import GradCAM
model_2d = DenseNet121(spatial_dims=2, in_channels=1, out_channels=1)
cam = GradCAM(nn_module=model_2d, target_layers="class_layers.relu")
result = cam(x=torch.rand((1, 1, 64, 64)))
thanks for looking into this @thatgeeman, indeed it's already supported. I'm closing this and please help update one of the test cases for the single channel output if you are interested... https://github.com/Project-MONAI/MONAI/blob/7614aca16617a8f0350a206dd57f7a9bfca66fd4/tests/test_vis_gradcam.py#L103
Discussed in https://github.com/Project-MONAI/MONAI/discussions/5528
(the class score function and the subclasses are not compatible with such input models
https://github.com/Project-MONAI/MONAI/blob/5e6f105ff1d40266debfbd9774a9a0bdbe4d817a/monai/visualize/class_activation_maps.py#L125-L126)