Project-MONAI / research-contributions

Implementations of recent research prototypes/demonstrations using MONAI.
https://monai.io/
Apache License 2.0
1.02k stars 334 forks source link

SWIN UNETR forward_part1 norm layer erroring out #194

Closed alpergel closed 1 year ago

alpergel commented 1 year ago

Hello, Im feeding the network data with size of [1,128,128,128] but I keep getting the following error: "RuntimeError: Given normalized_shape=[48], expected input with shape [*, 48], but got input of size[48, 64, 64, 64]". Is there a model setting that I am not setting correctly?

Thank you so much in advance!

Environment (please complete the following information):

peterhessey commented 1 year ago

Linking this discussion here as I believe they're related. It seems that the pre-trained weights being used for SwinUNet are not being set up correctly for all datasets:

I'm trying to replicate the Auto3dSeg results on the medical decathlon prostate data (task_05). However, I'm running into the following error during the SwinUnet training stage:

RuntimeError: Error(s) in loading state_dict for SwinUNETR:
  size mismatch for swinViT.patch_embed.proj.weight: copying a param with shape torch.Size([48, 1, 2, 2, 2]) from checkpoint, >the shape in current model is torch.Size([48, 2, 2, 2, 2]).
  size mismatch for encoder1.layer.conv1.conv.weight: copying a param with shape torch.Size([48, 1, 3, 3, 3]) from >checkpoint, the shape in current model is torch.Size([48, 2, 3, 3, 3]).
  size mismatch for encoder1.layer.conv3.conv.weight: copying a param with shape torch.Size([48, 1, 1, 1, 1]) from >checkpoint, the shape in current model is torch.Size([48, 2, 1, 1, 1]).
tangy5 commented 1 year ago

Which codebase are you using, the BRATS segmentation or the BTCV? The pretrained weights can be different on different tasks, BRATS task used 128x128x128 as input, BTCV CT segmentation used 96x96x96. The size might matters here.

peterhessey commented 1 year ago

@tangy5 I'm not sure which codebases you are referring to. I am just trying to using the Auto3dSeg AutoRunner with the following command:

python -m monai.apps.auto3dseg AutoRunner run --input='./task.yaml'

In the generated train.py for each of the SwinUnet folds, it appears the the weights are being downloaded from the following URL:

"https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/swin_unetr.base_5000ep_f48_lr2e-4_pretrained.pt"

Does this answer your question?

mingxin-zheng commented 1 year ago

The issue seems resolved in another thread. I'm closing this one.

peterhessey commented 1 year ago

@mingxin-zheng can you please link the thread where this was resolved?

mingxin-zheng commented 1 year ago

Hi @peterhessey I believe this is the PR that it got fixed: https://github.com/Project-MONAI/research-contributions/pull/202 And it is updated in the dev branch of MONAI: https://github.com/Project-MONAI/MONAI/pull/5973