CSAILVision / NetDissect-Lite

Light version of Network Dissection for Quantifying Interpretability of Networks
215 stars 52 forks source link

Torch source change: repo incompatible with versions 0.5.0 and 1.0.0 #3

Open philipclaesson opened 5 years ago

philipclaesson commented 5 years ago

It seems the repo is suffering from changes in Torch source code, more specifically in the use of the BatchNorm2d object put possibly on more places.

The repo works fine for the resnet18 model, but downloading and using the pretrained models for resnet50 and densenet161 yields errors:

AttributeError: 'BatchNorm2d' object has no attribute 'track_running_stats'

There are also a set of SourceChangeWarnings, among other:

/jet/var/python/lib/python3.6/site-packages/torch/serialization.py:425: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. 
you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the chang
es.

Tried running both Pytorch versions 0.5.0 and 1.0.0. This thread suggests downgrading Pytorch to 0.3 would make it work, will update if I get the possibility to do so.

Error Log

Traceback (most recent call last):
  File "main.py", line 11, in <module>
    features, maxfeature = fo.feature_extraction(model=model)
  File "/jet/prs/NetDissect-Lite/feature_operation.py", line 67, in feature_extraction
    logit = model.forward(input_var)
  File "/jet/var/python/lib/python3.6/site-packages/torchvision/models/densenet.py", line 157, in forward
    features = self.features(x)
  File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/container.py", line 91, in forward
    input = module(input)
  File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 65, in forward
    self.training or not self.track_running_stats,
  File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/module.py", line 518, in __getattr__
    type(self).__name__, name))
AttributeError: 'BatchNorm2d' object has no attribute 'track_running_stats'
sjtubblythe commented 5 years ago

I had same issue. Downgrading torch to 0.3.1 works for me.

snorlaxse commented 5 years ago

I had same issue. Downgrading torch to 0.3.1 works for me.

After Downgrading torch to 0.3.1, and run the 'main.py' .

RuntimeError: CUDNN_STATUS_EXECUTION_FAILED

How to solve?

sunyiyou commented 5 years ago

I had same issue. Downgrading torch to 0.3.1 works for me.

After Downgrading torch to 0.3.1, and run the 'main.py' .

RuntimeError: CUDNN_STATUS_EXECUTION_FAILED

How to solve?

This is mostly like an issue of your CUDA. For example, if you are using 2080Ti and CUDA10, pytorch 0.3 is not supportive enough. Since it is an 'old' repo, you might have to try the 'old' settings like 1080Ti and CUDA8 where the environment is fully tested.

cyizhuo commented 4 years ago

Don't know if it helps or not, but I created conda env with:

conda install scipy==1.0.0 (must be installed first) conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

and Net-Dissection-Lite worked perfect (on linux, never successed on windows).

AwesomeLemon commented 4 years ago

@cyizhuo that worked perfectly, thank you so much!

cyizhuo commented 4 years ago

@cyizhuo that worked perfectly, thank you so much!

Glad to know that~