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

解决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')- Linux/macOS终端执行:
克隆对应版本的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
相关产品推荐
相关产品推荐

