Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid layer name: module.densenet121.features.denseblock4.denselayer16.conv.2 #8

Open
rajdeinno opened this issue May 27, 2019 · 12 comments

Comments

@rajdeinno
Copy link

Hi,

I got the below error while running denseNet_localization.py file.

Traceback (most recent call last):
  File "/media/administrator/D/XRay/CheXnet_Demo/denseNet_localization.py", line 227, in <module>
    output = gcam.generate(target_layer="module.densenet121.features.denseblock4.denselayer16.conv.2")
  File "/media/administrator/D/XRay/CheXnet_Demo/denseNet_localization.py", line 186, in generate
    fmaps = self._find(self.all_fmaps, target_layer)
  File "/media/administrator/D/XRay/CheXnet_Demo/denseNet_localization.py", line 174, in _find
    raise ValueError('Invalid layer name: {}'.format(target_layer))
ValueError: Invalid layer name: module.densenet121.features.denseblock4.denselayer16.conv.2

any help would be really appriciated.. Thanks in advance..

@thtang
Copy link
Owner

thtang commented May 27, 2019

Do you use Pytorch==0.2.0 and torchvision==0.2.0 ?

@rajdeinno
Copy link
Author

rajdeinno commented May 28, 2019

I am using the below version since I had some problem with torchvision 0.2.0.

torch==1.1.0
torchvision==0.2.2

Additional info:
I ran my training by using the below requirements in Ubuntu 16.04.

python== 3.5.6
pip 19.1.1
pkg-resources 0.0.0
setuptools 41.0.1
wheel 0.33.4

cycler==0.10.0
decorator==4.4.0
imageio==2.5.0
joblib==0.13.2
matplotlib==2.1.1
networkx==2.3
numpy==1.13.3
opencv-python==3.4.0.12
pandas==0.24.2
Pillow==6.0.0
pyparsing==2.4.0
python-dateutil==2.8.0
pytz==2019.1
PyWavelets==1.0.3
scikit-image==0.13.1
scikit-learn==0.21.1
scipy==1.0.0
six==1.12.0
torch==1.1.0
torchvision==0.2.2

@rajdeinno
Copy link
Author

rajdeinno commented May 28, 2019

If I use torchvision 0.2.0 and torch==1.0.1 I get the following error.

warn("The default mode, 'constant', will be changed to 'reflect' in "
0
Traceback (most recent call last):
  File "denseNet_localization.py", line 76, in <module>
    model = DenseNet121(8).cuda()
  File "denseNet_localization.py", line 65, in __init__
    self.densenet121 = torchvision.models.densenet121(pretrained=True)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 26, in densenet121
    **kwargs)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 142, in __init__
    bn_size=bn_size, growth_rate=growth_rate, drop_rate=drop_rate)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 98, in __init__
    layer = _DenseLayer(num_input_features + i * growth_rate, growth_rate, bn_size, drop_rate)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 77, in __init__
    self.add_module('norm.1', nn.BatchNorm2d(num_input_features)),
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torch/nn/modules/module.py", line 180, in add_module
    raise KeyError("module name can't contain \".\"")
KeyError: 'module name can\'t contain "."'

So I have upgraded torchvision to 0.2.2. and torch==1.1.0. and my train went successful. When I try to run denseNet_localization.py file then I got the above error.

@thtang
Copy link
Owner

thtang commented May 28, 2019

Ok, so it seems that the errors are just caused by the different version of packages.

@rajdeinno
Copy link
Author

rajdeinno commented May 28, 2019

It worked for me after I changed the name in denseNet_localization.py module.densenet121.features.denseblock4.denselayer16.conv.2 to module.densenet121.features.denseblock4.denselayer16.conv2

And I had some package version issues as well.

@rajdeinno
Copy link
Author

rajdeinno commented May 28, 2019 via email

@rajdeinno rajdeinno reopened this May 28, 2019
@mochita314
Copy link

I changed
module.densenet121.features.denseblock4.denselayer16.conv.2 to module.densenet121.features.denseblock4.denselayer16.conv2
but still have same problem.
What should I do ... ??

I'm using
torch (1.0.1.post2)
torchvision (0.2.2.post3)

  File "denseNet_localization.py", line 247, in <module>
    output = gcam.generate(target_layer="module.densenet121.features.denseblock4.denselayer16.conv2")
  File "denseNet_localization.py", line 211, in generate
    fmaps = self._find(self.all_fmaps, target_layer)
  File "denseNet_localization.py", line 199, in _find
    raise ValueError('Invalid layer name: {}'.format(target_layer))
ValueError: Invalid layer name: module.densenet121.features.denseblock4.denselayer16.conv2```

@sp7414
Copy link

sp7414 commented Nov 6, 2020

I changed
module.densenet121.features.denseblock4.denselayer16.conv.2 to module.densenet121.features.denseblock4.denselayer16.conv2
but still have same problem.
What should I do ... ??

I'm using
torch (1.0.1.post2)
torchvision (0.2.2.post3)

  File "denseNet_localization.py", line 247, in <module>
    output = gcam.generate(target_layer="module.densenet121.features.denseblock4.denselayer16.conv2")
  File "denseNet_localization.py", line 211, in generate
    fmaps = self._find(self.all_fmaps, target_layer)
  File "denseNet_localization.py", line 199, in _find
    raise ValueError('Invalid layer name: {}'.format(target_layer))
ValueError: Invalid layer name: module.densenet121.features.denseblock4.denselayer16.conv2```

have you solved this problem? I'm facing the same issue.

@ankitdata
Copy link

I changed
module.densenet121.features.denseblock4.denselayer16.conv.2 to module.densenet121.features.denseblock4.denselayer16.conv2
but still have same problem.
What should I do ... ??
I'm using
torch (1.0.1.post2)
torchvision (0.2.2.post3)

  File "denseNet_localization.py", line 247, in <module>
    output = gcam.generate(target_layer="module.densenet121.features.denseblock4.denselayer16.conv2")
  File "denseNet_localization.py", line 211, in generate
    fmaps = self._find(self.all_fmaps, target_layer)
  File "denseNet_localization.py", line 199, in _find
    raise ValueError('Invalid layer name: {}'.format(target_layer))
ValueError: Invalid layer name: module.densenet121.features.denseblock4.denselayer16.conv2```

have you solved this problem? I'm facing the same issue.

see this issue might helpfull

@Aliktk
Copy link

Aliktk commented Jun 8, 2021

If I use torchvision 0.2.0 and torch==1.0.1 I get the following error.

warn("The default mode, 'constant', will be changed to 'reflect' in "
0
Traceback (most recent call last):
  File "denseNet_localization.py", line 76, in <module>
    model = DenseNet121(8).cuda()
  File "denseNet_localization.py", line 65, in __init__
    self.densenet121 = torchvision.models.densenet121(pretrained=True)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 26, in densenet121
    **kwargs)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 142, in __init__
    bn_size=bn_size, growth_rate=growth_rate, drop_rate=drop_rate)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 98, in __init__
    layer = _DenseLayer(num_input_features + i * growth_rate, growth_rate, bn_size, drop_rate)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 77, in __init__
    self.add_module('norm.1', nn.BatchNorm2d(num_input_features)),
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torch/nn/modules/module.py", line 180, in add_module
    raise KeyError("module name can't contain \".\"")
KeyError: 'module name can\'t contain "."'

So I have upgraded torchvision to 0.2.2. and torch==1.1.0. and my train went successful. When I try to run denseNet_localization.py file then I got the above error.

Hello @rajdeinno how did u solve this error please healp me in this regard.
Thanks @rajdeinno

@ankitdata
Copy link

If I use torchvision 0.2.0 and torch==1.0.1 I get the following error.

warn("The default mode, 'constant', will be changed to 'reflect' in "
0
Traceback (most recent call last):
  File "denseNet_localization.py", line 76, in <module>
    model = DenseNet121(8).cuda()
  File "denseNet_localization.py", line 65, in __init__
    self.densenet121 = torchvision.models.densenet121(pretrained=True)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 26, in densenet121
    **kwargs)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 142, in __init__
    bn_size=bn_size, growth_rate=growth_rate, drop_rate=drop_rate)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 98, in __init__
    layer = _DenseLayer(num_input_features + i * growth_rate, growth_rate, bn_size, drop_rate)
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torchvision/models/densenet.py", line 77, in __init__
    self.add_module('norm.1', nn.BatchNorm2d(num_input_features)),
  File "/home/administrator/Desktop/Projects/xray/chexnet/setup3.5/lib/python3.5/site-packages/torch/nn/modules/module.py", line 180, in add_module
    raise KeyError("module name can't contain \".\"")
KeyError: 'module name can\'t contain "."'

So I have upgraded torchvision to 0.2.2. and torch==1.1.0. and my train went successful. When I try to run denseNet_localization.py file then I got the above error.

Hello @rajdeinno how did u solve this error please healp me in this regard.
Thanks @rajdeinno

check this.
#7 (comment)

@Aliktk
Copy link

Aliktk commented Jun 15, 2021

Hi Tang, I am able to generate the bound_box.txt file after I execute the denseNet_localization.pyfile. how to visualize the bound box text file into the input image? as you mentioned in ground-truth label (red) and its prediction (blue). Thanks in advance.. Please assist me on this..

Sent from my iPhone
On 28-May-2019, at 17:57, T.H. Tang @.***> wrote: It seem that the errors are just caused by the different version of packages. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

@rajdeinno hello sir after generating BB file how you print BB on that image with heatmap of that image?
Pleae help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants