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

Can't load UNETR pretrained model correctly #170

Open
chaoscls opened this issue Dec 23, 2022 · 3 comments
Open

Can't load UNETR pretrained model correctly #170

chaoscls opened this issue Dec 23, 2022 · 3 comments

Comments

@chaoscls
Copy link

when I load UNETR pretrained model from https://drive.google.com/file/d/1kR5QuRAuooYcTNLMnMj80Z9IgSs8jtLO/view?usp=sharing, I got error:

raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for UNETR:
Unexpected key(s) in state_dict: "vit.patch_embedding.cls_token", "encoder2.blocks.0.1.conv3.conv.weight", "encoder2.blocks.1.1.conv3.conv.weight", "encoder3.blocks.0.1.conv3.conv.weight".

How can I fix it? Thanks!

@tangy5
Copy link
Contributor

tangy5 commented Jan 4, 2023

Hi @chaoscls , thanks for the question. The released model should be the one for training BTCV, 13 organs segmentation. I guess if the number of input channels are different (e.g., load the pre-trained model to train other tasks which are not BTCV dataset), there will an issue, especially for the patch embedding weights.

For a quick solution, you can either use strict=false when loading pre-trained weights, or load the model without patch embedding layer keys if the model is used for training other datasets.

For a longer time maintenance, we are working on releasing a model for flexible input/output channels. So that it can be used for other tasks. Note that the current pre-trained model is supervised trained on multi-organ segmentation.

Thank you.

@RR-N
Copy link

RR-N commented May 18, 2023

Just noting +1 on the need for more flexible i/o channels -- we were considering UNETR for use on microscopy images and wanted to run a quick test before we commit to training and couldn't due to this same issue.

@Cocofeat
Copy link

I fix it with the monai==0.7.0

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

4 participants