-
Notifications
You must be signed in to change notification settings - Fork 9
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
SegmentAnything loading state_dict error #57
Comments
First, please ensure that your md5 sam_hq_vit_l.pth The correct MD5 hash should be: MD5 (sam_hq_vit_l.pth) = 08947267966e4264fb39523eccc33f86 If the hash matches, the file is downloaded correctly and is not corrupted. Next, confirm that pip install git+https://github.com/SysCV/sam-hq.git This will ensure that |
|
I think I find the solution:
from segment_anything import sam_model_registry, SamPredictor, SamAutomaticMaskGenerator to from segment_anything_hq import sam_model_registry, SamPredictor, SamAutomaticMaskGenerator Now the text prompt segmentation works. |
The setup.py file contains the line "segment-anything @ git+https://github.com/SysCV/sam-hq.git". When you run pip install -e ., it installs the package from the GitHub repository using the alias segment-anything. This line explicitly installs the SAM-HQ package from the SysCV repository but labels it as segment-anything. This prevents any conflict with Meta’s segment-anything package and eliminates the need for a separate package, such as segment-anything-hq. |
As mentioned earlier, I have already tried reinstalling sam-hq using pip install git+https://github.com/SysCV/sam-hq.git, but unfortunately, it did not work for me. The load state_dict continues to reference the original Facebook SAM. To ensure I hadn't missed anything, I repeated the entire process from scratch on a new Windows machine, and I install Segment Anything specifically from SysCV using I realized that the issue might have been due to the installation tutorial. As the github tutorial mentioned, before running In summary, here are the steps I followed to get Annolid working:
|
Thank you for sharing your experience! I’m glad to hear that you successfully installed Annolid and it’s working for you. I’m not sure about the environment you’re using to run Annolid, but we recommend using Conda, as outlined in the installation guide: Installation Instructions. |
I successfully installed Annolid on Windows by following the documentation:
The GUI runs well, and I can load videos without any problems. However, when I tried using SAM-based text prompt segmentation by following (https://www.youtube.com/watch?v=ry9bnaajKCs), I encountered an error:
Traceback (most recent call last):
File "d:\annolid\annolid\gui\app.py", line 649, in _grounding_sam
self.canvas.predictAiRectangle(prompt_text)
File "d:\annolid\annolid\gui\widgets\canvas.py", line 274, in predictAiRectangle
self.sam_hq_model = SamHQSegmenter()
^^^^^^^^^^^^^^^^
File "d:\annolid\annolid\segmentation\SAM\sam_hq\sam_hq.py", line 41, in init
self.sam = sam_model_registrymodel_type
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\miniconda3\envs\annolid-env\Lib\site-packages\segment_anything\build_sam.py", line 28, in build_sam_vit_l
return _build_sam(
^^^^^^^^^^^
File "D:\miniconda3\envs\annolid-env\Lib\site-packages\segment_anything\build_sam.py", line 106, in _build_sam
sam.load_state_dict(state_dict)
File "D:\miniconda3\envs\annolid-env\Lib\site-packages\torch\nn\modules\module.py", line 2215, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Sam:
Unexpected key(s) in state_dict: "mask_decoder.hf_token.weight", "mask_decoder.hf_mlp.layers.0.weight", "mask_decoder.hf_mlp.layers.0.bias", "mask_decoder.hf_mlp.layers.1.weight", "mask_decoder.hf_mlp.layers.1.bias", "mask_decoder.hf_mlp.layers.2.weight", "mask_decoder.hf_mlp.layers.2.bias", "mask_decoder.compress_vit_feat.0.weight", "mask_decoder.compress_vit_feat.0.bias", "mask_decoder.compress_vit_feat.1.weight", "mask_decoder.compress_vit_feat.1.bias", "mask_decoder.compress_vit_feat.3.weight", "mask_decoder.compress_vit_feat.3.bias", "mask_decoder.embedding_encoder.0.weight", "mask_decoder.embedding_encoder.0.bias", "mask_decoder.embedding_encoder.1.weight", "mask_decoder.embedding_encoder.1.bias", "mask_decoder.embedding_encoder.3.weight", "mask_decoder.embedding_encoder.3.bias", "mask_decoder.embedding_maskfeature.0.weight", "mask_decoder.embedding_maskfeature.0.bias", "mask_decoder.embedding_maskfeature.1.weight", "mask_decoder.embedding_maskfeature.1.bias", "mask_decoder.embedding_maskfeature.3.weight", "mask_decoder.embedding_maskfeature.3.bias".
The text was updated successfully, but these errors were encountered: