You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行HuggingFace深度估计管道示例时遇ValueError报错

解决DepthEstimationPipeline加载LiheYoung/depth-anything-base-hf时的ValueError问题

错误原因

你遇到的ValueError是因为当前安装的Transformers版本未内置depth_anything模型架构的支持,属于版本兼容问题。

解决步骤

  • 升级Transformers到最新稳定版
    运行以下命令更新Transformers,新版本已添加对Depth Anything模型的支持:

    pip install --upgrade transformers
    
  • 确认依赖完整性
    确保安装了运行深度估计任务所需的基础依赖:

    pip install torch pillow
    
  • 若仍报错,手动注册模型架构(可选)
    如果升级后问题依旧,可能需要手动注册模型架构:

    from transformers import AutoConfig, AutoModelForDepthEstimation
    from transformers.models.auto.modeling_auto import register_auto_model
    
    # 注册Depth Anything模型架构
    AutoConfig.register("depth_anything", AutoConfig)
    register_auto_model(AutoModelForDepthEstimation, "depth_anything")
    
    # 重新加载pipeline
    depth_estimator = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf")
    

内容的提问来源于stack exchange,提问作者ChaosPredictor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 00:02:07