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

Error when pass norm_name = 'layer' for swin_unetr #196

Closed
DiDiDD opened this issue Mar 3, 2023 · 4 comments
Closed

Error when pass norm_name = 'layer' for swin_unetr #196

DiDiDD opened this issue Mar 3, 2023 · 4 comments

Comments

@DiDiDD
Copy link

DiDiDD commented Mar 3, 2023

Hello,

I wanted to apply layer norm for model swin_unetr by setting norm_name='layer', but I got errors TypeError: LayerNorm.init() missing 1 required positional argument: 'normalized_shape'.

But i got no problems when applying batch norm and i just set norm_name='batch'.

model_su = SwinUNETR(img_size = (512, 512), in_channels=3, out_channels=3,
depths=depths,
num_heads=(3, 6, 12, 24),
feature_size=12,
norm_name= norm_name,
drop_rate=0.0,
attn_drop_rate=0.0,
dropout_path_rate=0.0,
normalize=True,
use_checkpoint=False,
spatial_dims=2,
downsample='merging')

Can someone help me, please? Many thanks!

@tangy5
Copy link
Contributor

tangy5 commented Mar 13, 2023

Emmm, Did you use the latest MONAI repo? You can try update the dependencies. The layer norm should work. Thanks for the interests of the work.

@DiDiDD
Copy link
Author

DiDiDD commented Mar 16, 2023

Thank you for the reply! I've tried to run with updated dependencies now (which I followed the steps on monai's web), but it still pops the same error. May I ask if swin_unetr with layer norm can run on your side, please? Many thanks!

@tangy5
Copy link
Contributor

tangy5 commented Mar 20, 2023

Yes, the Layer norm work all good, we also have the unit test and integration tests covers the SwinUNETR network in MONAI repo.

I guess the Pytorch version possibly matters, you could do a new env and install the monai with pytorch.

@DiDiDD DiDiDD closed this as completed Jun 6, 2023
@MiguelMonteiro
Copy link

MiguelMonteiro commented Dec 6, 2023

I got the same error using monai 1.3.0 and pytorch 2.0.1 when attempting to use DenseNet. It seems layer norm needs to know the shape of the input and nowhere in the norm layer factory code is this passed/inferred.
Simple code to reproduce

from monai.networks.nets.densenet import densenet121
model = densenet121(spatial_dims=3, in_channels=1, out_channels=2048, norm="layer")

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

3 participants