TensorFlow与TensorFlow Object Detection API版本兼容及模块缺失报错咨询
问题解决指南
一、先解决ModuleNotFoundError: No module named 'object_detection'
- 检查API安装完整性:
- 虽然你用pip装了
tensorflow-object-detection-api==0.1.1,但这个包需要完整安装才能让Python识别到object_detection模块。打开虚拟环境的site-packages文件夹,确认里面有没有object_detection目录;如果没有,重新运行安装命令:pip install tensorflow-object-detection-api==0.1.1 - 若安装后仍找不到,手动添加模块路径:
在代码开头加入以下内容(替换成你虚拟环境中object_detection所在的实际路径):
或者在终端运行代码前设置环境变量:import sys sys.path.append("/你的虚拟环境路径/lib/pythonX.X/site-packages/tensorflow_object_detection_api")export PYTHONPATH=$PYTHONPATH:/你的虚拟环境路径/lib/pythonX.X/site-packages/tensorflow_object_detection_api
- 虽然你用pip装了
- 确认虚拟环境已激活:运行代码前必须确保激活了安装这些包的虚拟环境,否则Python会调用系统环境的包,自然找不到目标模块。
二、版本兼容性说明
tensorflow-object-detection-api==0.1.1是2018年左右发布的老旧版本,仅兼容TensorFlow 1.x(比如1.13.x、1.12.x),完全不支持最新的TensorFlow 2.x,这也是你出问题的核心原因之一:
- 若坚持用这个API版本,必须卸载当前TensorFlow,安装对应版本:
pip uninstall tensorflow pip install tensorflow==1.13.1 - 更推荐升级API到适配TensorFlow 2.x的版本:
最新版API能和你安装的TensorFlow兼容,还能避免旧版本的各种bug。pip uninstall tensorflow-object-detection-api pip install tensorflow-object-detection-api
内容的提问来源于stack exchange,提问作者Ishaan Gupta
相关产品推荐
相关产品推荐

