Google Colab运行TensorFlow 2 setup.py超时,如何安装Object Detection API
Google Colab安装TensorFlow Object Detection API超时问题解决方案
以下步骤可完全规避python -m pip install .阶段的超时问题:
- 第一步:配置Colab运行时
点击顶部菜单栏「修改」→「笔记本设置」,硬件加速器选择「GPU」后保存,等待运行时重启完成。 - 第二步:提前安装核心依赖并配置国内镜像源
执行以下命令完成基础依赖预装,避免后续批量安装触发网络超时:
!pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple !pip install tensorflow==2.15.0 opencv-python matplotlib pillow lxml Cython contextlib2 pycocotools
- 第三步:浅克隆TensorFlow Models仓库
跳过完整仓库的历史提交下载,大幅减少克隆耗时:
!git clone --depth 1 https://github.com/tensorflow/models.git
- 第四步:手动编译Protobuf文件
避免setup脚本自动下载Protobuf编译器触发超时:
%cd /content/models/research !apt-get install -y protobuf-compiler !protoc object_detection/protos/*.proto --python_out=.
- 第五步:跳过依赖检测执行安装
核心依赖已提前预装,安装时跳过依赖检查即可避免重复拉取资源卡顿:
!cp object_detection/packages/tf2/setup.py . !pip install --no-deps .
- 第六步:验证安装结果
执行测试命令,输出OK即代表安装成功:
!python object_detection/builders/model_builder_tf2_test.py
补充说明:如果验证时出现个别依赖版本不兼容的报错,直接根据报错提示安装对应版本的依赖包即可,无需重新执行完整安装流程。
内容的提问来源于stack exchange,提问作者Fredrik
相关产品推荐
相关产品推荐

