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
相关推荐
LaughingZhu5 天前
Product Hunt 每日热榜 | 2026-09-19
人工智能·深度学习·神经网络·搜索引擎·百度
猎头南楼5 天前
知识社区推荐系统实践:新用户冷启动与长短期兴趣建模的挑战 资深推荐算法工程师
人工智能·深度学习·算法·机器学习
高洁015 天前
未来三年,AI 落地的五个确定性判断一
人工智能·深度学习·机器学习·transformer·知识图谱
`流年づ5 天前
人工智能学习笔记 - 补充
人工智能·笔记·深度学习·学习
成为深度学习高手5 天前
CrossLinear:即插即用的跨相关嵌入,让线性模型也能用好外生变量
人工智能·python·深度学习·数据挖掘
科技苑5 天前
如何打造一个高效的全栖内容制作生态系统?
深度学习
江屿风6 天前
【认识深度学习】【深度学习分类与计算机视觉任务要点解析】流食般投喂
大数据·人工智能·深度学习·计算机视觉·目标跟踪·自然语言处理·语音识别
童园管理札记6 天前
从政策驱动到课堂落地:2026年“人工智能+教育”全景解读与技术实践指南
人工智能·python·深度学习·职场和发展·学习方法
Ivanqhz6 天前
SVD++算法
java·服务器·网络·深度学习·神经网络