uni-medical / SAM-Med3D

SAM-Med3D: An Efficient General-purpose Promptable Segmentation Model for 3D Volumetric Medical Image
Apache License 2.0
525 stars 68 forks source link

medim_infer.py ERROR in medim.create_model method #92

Open ZhengWei0918 opened 1 week ago

ZhengWei0918 commented 1 week ago

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 commented 4 days ago

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

ZhengWei0918 commented 4 days ago

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

not yet

Skrill2001 commented 3 days ago

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

ZhengWei0918 commented 3 days ago

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 commented 3 days ago

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 commented 3 days ago

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..