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
相关推荐
jay神1 小时前
深度学习的优化器应该怎么选?
人工智能·python·深度学习·毕业设计·课程设计
YOLO数据集集合13 小时前
一站式AI数据自动化标注与训练平台:零门槛玩转YOLO全系列模型
人工智能·深度学习·yolo·ai·自动化·数据集·标注软件
史上最甜的躯16 小时前
医疗影像分析与深度学习-导论
深度学习·医疗检测
铅笔侠_小龙虾17 小时前
深度学习阶段总结(2)--矩阵
深度学习·矩阵
手写码匠20 小时前
华为云Flexus+DeepSeek征文|Dify 多 Agent 灰度发布实战:让每一次变更都“小步快跑、随时可回滚“
人工智能·深度学习·算法·aigc
TonyLee01721 小时前
神经网络门控机制探讨
人工智能·深度学习·神经网络
JAI科研1 天前
Deepseek Agent Harness教程(二) | DeepSeek Harness 设计思路
人工智能·深度学习·算法·机器学习·自然语言处理·transformer·vllm
还不秃顶的计科生1 天前
具身智能论文学习10:π0: A Vision-Language-Action Flow Model for General Robot Control
人工智能·深度学习·算法·机器学习·语言模型·vla·vlm
段一凡-华北理工大学1 天前
AI推动工业智能化转型~系列文章24:钢铁工业 AI 全景图:从原料场到轧机的场景地图
人工智能·深度学习·模型生命周期·钢铁工业·ai全景
chen_zn952 天前
《VLA 系列》Human-to-Robot Transfer | 人类视频共训练 | 跨本体涌现迁移 | 论文解析
人工智能·深度学习·transformer·具身智能·vla