idiap / fullgrad-saliency

Full-gradient saliency maps
Other
201 stars 31 forks source link

ResNet Incompatibility #1

Closed kemaloksuz closed 4 years ago

kemaloksuz commented 4 years ago

Hi, I think the code is not compatible with the ResNet currently, since once I try to run it with a pretained ResNet model from torchvision, I have the following error:

RuntimeError: Given groups=1, weight of size 256 64 1 1, expected input[1, 256, 56, 56] to have 64 channels, but got 256 channels instead

When I check the code you assume that "modules are arranged in "chronological" fashion" in full grad.py. Maybe the residual connections in ResNet conflicts with this assumption. So, do you see a quick fix for this problem and are you planning to fix this?

suraj-srinivas commented 4 years ago

Hi, yes you are correct, the code is incompatible with ResNets right now. I do not see a quick fix, as making it compatible with ResNets or any general connectivity pattern would involve making major changes to the code structure. I am indeed planning to fix this though.

In the meantime, you may modify simple_fullgrad.py by replacing the functionality of _getFeatures() method by obtaining intermediate features from the ResNet model itself, and feeding these features to _getGradients(). i.e.; it might help to implement something like out, features = self.model.getFeatures(image) to replace line 97 in simple_fullgrad.py.

suraj-srinivas commented 4 years ago

I've (finally) added support for ResNet and ResNeXt architectures. Closing this issue as a result.