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

TensorFlow Object Detection API安装验证报错:找不到official.legacy模块

error message

解决TensorFlow Object Detection API中找不到official.legacy模块的问题
  • 安装兼容版本的tf-models-official
    新版本的tf-models-official已移除official.legacy模块,需要安装保留该模块的旧版本,执行命令:

    pip install tf-models-official==2.11.0
    

    同时确保TensorFlow版本与该版本匹配,建议安装TensorFlow 2.11.x版本。

  • 确保Object Detection API路径被添加到PYTHONPATH
    即使安装了tf-models-official,仍需将TensorFlow Models仓库中的research和slim目录加入Python路径:

    • Linux/macOS终端执行:
      export PYTHONPATH=$PYTHONPATH:/your/path/to/tensorflow/models/research:/your/path/to/tensorflow/models/research/slim
      
    • Windows终端执行:
      set PYTHONPATH=C:\your\path\to\tensorflow\models\research;C:\your\path\to\tensorflow\models\research\slim
      

    或者在验证脚本开头添加路径:

    import sys
    sys.path.append('/your/path/to/tensorflow/models/research')
    sys.path.append('/your/path/to/tensorflow/models/research/slim')
    
  • 克隆对应版本的TensorFlow Models仓库
    若直接克隆最新版Models仓库,可能与安装的tf-models-official版本不兼容,建议切换到对应标签版本:

    git clone https://github.com/tensorflow/models.git
    cd models
    git checkout v2.11.0
    

    之后重新执行官方文档中的安装步骤(如编译protos文件)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 20:08:06