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

medim_infer.py ERROR in medim.create_model method #92

Open
ZhengWei0918 opened this issue Nov 15, 2024 · 6 comments
Open

medim_infer.py ERROR in medim.create_model method #92

ZhengWei0918 opened this issue Nov 15, 2024 · 6 comments

Comments

@ZhengWei0918
Copy link

ZhengWei0918 commented Nov 15, 2024

creating model SAM-Med3D
try to load pretrained weights from /home/weizheng/models/sam_med3d/sam_med3d.pth
Traceback (most recent call last):
File "/home/weizheng/SAM-Med3D/medim_infer.py", line 280, in
model = medim.create_model("SAM-Med3D",
File "/usr/local/anaconda3/envs/sammed3d/lib/python3.10/site-packages/medim/models/_factory.py", line 22, in create_model
return create_fn(pretrained=pretrained, checkpoint_path=checkpoint_path, **kwargs)
File "/usr/local/anaconda3/envs/sammed3d/lib/python3.10/site-packages/medim/models/sam_med3d.py", line 1257, in build_sam3D_vit_b_ori
load_pretrained_weights(model,
File "/usr/local/anaconda3/envs/sammed3d/lib/python3.10/site-packages/medim/models/_pretrain.py", line 86, in load_pretrained_weights
state_dict = torch.load(f, weights_only=True)
File "/usr/local/anaconda3/envs/sammed3d/lib/python3.10/site-packages/torch/serialization.py", line 1359, in load
raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.
(1) Re-running torch.load with weights_only set to False will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
(2) Alternatively, to load with weights_only=True please check the recommended steps in the following error message.
WeightsUnpickler error: Unsupported global: GLOBAL argparse.Namespace was not an allowed global by default. Please use torch.serialization.add_safe_globals([Namespace]) to allowlist this global if you trust this class/function.

Hi, when I run this file in either sam_med3d_turbo.pth or sam_med3d.pth, I got this error message in both cases. How to fix this, thanks.

@Skrill2001
Copy link

I have the same problem, I want to know if you solved it?

@ZhengWei0918
Copy link
Author

I have the same problem, I want to know if you solved it?

not yet

@Skrill2001
Copy link

If you set weights_only=False, it seems to work successfully, although a warning may appear.

@ZhengWei0918
Copy link
Author

ZhengWei0918 commented Nov 20, 2024

If you set weights_only=False, it seems to work successfully, although a warning may appear.

Thanks, your solution works. But the result of medim_infer.py looks very strange:
image

the highlighted one is the gt, while the other one is the predicted one, have you ever gotten the similar result? (I'm using sam_med3d_turbo.pth offline)

@Skrill2001
Copy link

If you set weights_only=False, it seems to work successfully, although a warning may appear.

Thanks, your solution works. But the result of medim_infer.py looks very strange: image

the highlighted one is the gt, while the other one is the predicted one, have you ever gotten the similar result? (I'm using sam_med3d_turbo.pth offline)

It may be that my segmentation objects are not the same as yours, so I don't have the same situation, but I also don't get good segmentation results on my task by sam_med3d_turbo.pth.

@ZhengWei0918
Copy link
Author

If you set weights_only=False, it seems to work successfully, although a warning may appear.

Thanks, your solution works. But the result of medim_infer.py looks very strange: image
the highlighted one is the gt, while the other one is the predicted one, have you ever gotten the similar result? (I'm using sam_med3d_turbo.pth offline)

It may be that my segmentation objects are not the same as yours, so I don't have the same situation, but I also don't get good segmentation results on my task by sam_med3d_turbo.pth.

ok, maybe I'd like to look for and try other models then..

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

2 participants