MedCLIP icon indicating copy to clipboard operation
MedCLIP copied to clipboard

Pretrained Models do not load with pip release

Open paulgavrikov opened this issue 1 year ago • 6 comments

I installed the latest version of medclip via pip and am trying to load the pretrained models. However, when loading ResNet or ViT I get the following error

RuntimeError: Error(s) in loading state_dict for MedCLIPModel:
	Unexpected key(s) in state_dict: "text_model.model.embeddings.position_ids".

It works if I install the module directly from git.

Reproduce:

from medclip import MedCLIPModel, MedCLIPVisionModelViT, MedCLIPVisionModel

model = MedCLIPModel(vision_cls=MedCLIPVisionModel)
model.from_pretrained()

paulgavrikov avatar Jan 17 '24 14:01 paulgavrikov

same problem! Do u find any solution?

Weixiang-Sun avatar Jan 19 '24 06:01 Weixiang-Sun

same problem! Do u find any solution?

Yes, it works if you install directly from this repo pip install git+https://github.com/RyanWangZf/MedCLIP.git

paulgavrikov avatar Jan 19 '24 12:01 paulgavrikov

Why do I use pip install git+https://github.com/RyanWangZf/MedCLIP.git to produce Uploading 微信图片_20240121232226.png…

Spring24ch avatar Jan 21 '24 15:01 Spring24ch

same problem! Do u find any solution?

Spring24ch avatar Jan 21 '24 15:01 Spring24ch

same problem! Do u find any solution?

you may delete this key from the dict using 'del text_encoder_checkpoint["text_model.model.embeddings.position_ids"]'. This is because of the Mismatched transformers version.

EastMage avatar Mar 27 '24 01:03 EastMage

A fix would also be to not be strict with loading the models weights. for that you can just add strict=False in this file: https://github.com/RyanWangZf/MedCLIP/blob/main/medclip/modeling_medclip.py#L185

StefanDenn3r avatar Apr 12 '24 13:04 StefanDenn3r