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
相关推荐
半摆烂日常9 分钟前
自建WMS和买成品:三年成本对比
大数据·服务器·数据库·python·深度学习·低代码·numpy
zzzll111124 分钟前
RAG(检索增强生成)会不会消亡?
人工智能·深度学习·机器学习
机器学习之心2 小时前
基于残差融合WOA-LSTM-EKF的锂电池SOC估计方法
人工智能·深度学习·神经网络·锂电池soc估计·woa-lstm-ekf
ai小陈2 小时前
CUDA版本不匹配怎么办?深度学习GPU环境排查与修复指南
人工智能·深度学习·ai·gpu算力
月华路2 小时前
《模型不玄学》第21章 稳定性与偏置审计
人工智能·深度学习·机器学习
在所不辞兄5 小时前
【零基础学智能仿真-11】CatBoost——让材料类型和边界条件参与力学预测
人工智能·python·深度学习·神经网络·机器学习·工程技术
知识分享小能手14 小时前
深度学习学习教程,从入门到精通,深度学习中的正则化 — 完整知识点与代码示例(7)
人工智能·深度学习·学习
LaughingZhu14 小时前
Product Hunt 每日热榜 | 2026-09-05
人工智能·深度学习·神经网络·搜索引擎·百度
YOLO数据集集合17 小时前
无人机高分辨率多树种单木分割数据集 | 单木分割 无人机林业 树种识别 实例分割 点云 遥感数据集 深度学习 精准林业9047期
人工智能·深度学习·数据集·无人机·遥感数据集·点云数据集·树木分割
HyperAI超神经1 天前
SenseNova-U1.5-8B-MoT 统一生成与理解,解锁原生多模态创作;DeepSeek-V4-Flash-Vision-Exp 拓展视觉理解新能力
人工智能·深度学习·图像生成·多模态大模型·视觉推理