groundingdino load_model 报错:‘BertModel‘ object has no attribute ‘get_head_mask‘

如果出现报错:

shell 复制代码
Traceback (most recent call last):
  File "/root/autodl-tmp/Grounded-Segment-Anything/./my_demo.py", line 4, in <module>
    model = load_model("GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py", "./groundingdino_swint_ogc.pth")
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/util/inference.py", line 32, in load_model
    model = build_model(args)
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/__init__.py", line 17, in build_model
    model = build_func(args)
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py", line 374, in build_groundingdino
    model = GroundingDINO(
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py", line 109, in __init__
    self.bert = get_tokenlizer.get_pretrained_language_model(text_encoder_type, bert_base_uncased_path)
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/util/get_tokenlizer.py", line 31, in get_pretrained_language_model
    return BertModel.from_pretrained(text_encoder_type)
  File "/root/miniconda3/envs/asr_opt/lib/python3.10/site-packages/transformers/modeling_utils.py", line 4060, in from_pretrained
    checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(
  File "/root/miniconda3/envs/asr_opt/lib/python3.10/site-packages/transformers/modeling_utils.py", line 699, in _get_resolved_checkpoint_files
    raise OSError(
OSError: Can't load the model for 'bert-base-uncased'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'bert-base-uncased' is the correct path to a directory containing a file named pytorch_model.bin.
Segmentation fault (core dumped)

改用清华源:

pyhton 复制代码
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'

如果出现报错:

shell 复制代码
Notes:
- UNEXPECTED    :can be ignored when loading from different task/architecture; not ok if you expect identical arch.
Traceback (most recent call last):
  File "/root/autodl-tmp/Grounded-Segment-Anything/./my_demo.py", line 7, in <module>
    model = load_model("GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py", "./groundingdino_swint_ogc.pth")
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/util/inference.py", line 32, in load_model
    model = build_model(args)
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/__init__.py", line 17, in build_model
    model = build_func(args)
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py", line 374, in build_groundingdino
    model = GroundingDINO(
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/groundingdino.py", line 112, in __init__
    self.bert = BertModelWarper(bert_model=self.bert)
  File "/root/autodl-tmp/Grounded-Segment-Anything/GroundingDINO/groundingdino/models/GroundingDINO/bertwarper.py", line 29, in __init__
    self.get_head_mask = bert_model.get_head_mask
  File "/root/miniconda3/envs/asr_opt/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1928, in __getattr__
    raise AttributeError(
AttributeError: 'BertModel' object has no attribute 'get_head_mask'

降级 transformers 版本。

shell 复制代码
pip list | grep transformers
# transformers             5.3.0
shell 复制代码
pip install transformers==4.57.6
相关推荐
xiao5kou4chang6kai42 小时前
MATLAB机器学习、深度学习--从数据预处理到模型训练
深度学习·机器学习·matlab·数据预处理
renhongxia13 小时前
世界模型作为AGI落地底层底座的作用
人工智能·深度学习·生成对抗网络·自然语言处理·知识图谱·agi
计算机科研狗@OUC3 小时前
(cvpr26) AIMDepth: Asymmetric Image-Event Mamba for Monocular Depth Estimation
人工智能·深度学习·计算机视觉
β添砖java6 小时前
深度学习(22)网络中的网络NiN
人工智能·深度学习
Kobebryant-Manba6 小时前
深度学习时候d2l报错和使用问题
人工智能·深度学习
zhangfeng11337 小时前
deepspeed zero3 结合 llamafactory 微调 ,save_only_model: true 导致保存时候出错
开发语言·python·深度学习
大模型最新论文速读7 小时前
06-16 · LLM 最新论文速览
论文阅读·人工智能·深度学习·机器学习·自然语言处理
宝贝儿好8 小时前
【LLM】第二章:HuggingFace入门学习
人工智能·深度学习·神经网络·学习·算法·自然语言处理
Black蜡笔小新8 小时前
企业私有化AI训练推理一体工作站DLTM深度学习推理工作站全流程技术解析
人工智能·深度学习
Kobebryant-Manba9 小时前
学习门控循环单元gru
深度学习·学习·gru