赞
踩
在使用SAM模型进行推理的时候报错:
Some weights of the model checkpoint at bert-base-uncased were not used when initializing BertModel: ['cls.predictions.transform.dense.weight', 'cls.seq_relationship.weight', 'cls.predictions.transform.LayerNorm.weight', 'cls.predictions.transform.LayerNorm.bias', 'cls.predictions.bias', 'cls.predictions.transform.dense.bias', 'cls.seq_relationship.bias']
- This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
_IncompatibleKeys(missing_keys=[], unexpected_keys=['label_enc.weight'])
/root/miniconda3/envs/myconda/lib/python3.10/site-packages/transformers/modeling_utils.py:768: FutureWarning: The `device` argument is deprecated and will be removed in v5 of Transformers.
warnings.warn(
/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/utils/checkpoint.py:31: UserWarning: None of the inputs have requires_grad=True. Gradients will be None
warnings.warn("None of the inputs have requires_grad=True. Gradients will be None")
Traceback (most recent call last):
File "/root/Downloads/Grounded-Segment-Anything/grounded_sam_demo.py", line 203, in <module>
predictor = SamPredictor(sam_model_registry[sam_version](checkpoint=sam_checkpoint).to(device))
File "/root/Downloads/Grounded-Segment-Anything/segment_anything/segment_anything/build_sam.py", line 15, in build_sam_vit_h
return _build_sam(
File "/root/Downloads/Grounded-Segment-Anything/segment_anything/segment_anything/build_sam.py", line 105, in _build_sam
state_dict = torch.load(f)
File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/serialization.py", line 797, in load
with _open_zipfile_reader(opened_file) as opened_zipfile:
File "/root/miniconda3/envs/myconda/lib/python3.10/site-packages/torch/serialization.py", line 283, in __init__
super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory
网上查了一下都说是模型没有下载完整。
由于报错信息前面显示的是bert模型,一直以为是bert的问题,后面仔细观察是sam模型没有下载完整。
回忆起来了在执行这两步加载模型的时候ctrl+C打断了一次,打断后不会继续下载而是重新下载并命名为“原模型名(1)”导致推理时采用的模型是之前没有下载完整的模型。
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
解决办法:重新把要加载的模型下载完整.....
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。