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
相关推荐
智算菩萨1 小时前
多目标超启发式算法系统文献综述:人机协同大语言模型方法论深度精读
论文阅读·人工智能·深度学习·ai·多目标·综述
简单光学2 小时前
ISDM: 基于生成扩散模型的散射介质成像重建技术报告
深度学习·扩散模型·散射成像·分数匹配·随机微分方程
IT阳晨。2 小时前
PyTorch深度学习实践
人工智能·pytorch·深度学习
智算菩萨2 小时前
【How Far Are We From AGI】5 AGI的“道德罗盘“——价值对齐的技术路径与伦理边界
论文阅读·人工智能·深度学习·ai·接口·agi·对齐技术
Sakuraba Ema2 小时前
从零理解 MoE(Mixture of Experts)混合专家:原理、数学、稀疏性、专家数量影响与手写 PyTorch 实现
人工智能·pytorch·python·深度学习·数学·llm·latex
freewlt3 小时前
科技热点速递:AI技术集中爆发
人工智能·深度学习·计算机视觉
南宫乘风3 小时前
LLaMA-Factory 给 Qwen1.5 做 LoRA 微调 实战
人工智能·深度学习·llama
小陈phd4 小时前
多模态大模型学习笔记(二十一)—— 基于 Scaling Law方法 的大模型训练算力估算与 GPU 资源配置
笔记·深度学习·学习·自然语言处理·transformer
zm-v-159304339864 小时前
Python 气象数据处理从入门到精通:机器学习订正 + 深度学习预测完整教程
python·深度学习·机器学习
nap-joker4 小时前
【生物年龄age gap】基于影像的器官特异性衰老时钟预测人类疾病和死亡率
人工智能·深度学习·影像·生物年龄·age gap