前言
在前面文章,已经完成了在Docker里面运行代码,并且在外部的Pycharm中调试,基本上Tensorflow的官方教程上面简单的东西都可以跑,接下来开始整理目标检测。
目标检测首先就要认清楚两个东西,现在官方推荐使用models.official.vision进行,但目前位置文档较少,无法很好的开始。所以用版本1流行的models.research.object_detection,目前该模块已经添加了对版本2的支持,虽然已经弃用。
上面提到的仓库在下面连接
https://github.com/tensorflow/models/tree/master/official/vision
https://github.com/tensorflow/models/tree/master/research/object_detection
均来自models仓库
设置下镜像(可选)
为了国内安装速度快一些,不要总是失败,建议安装下镜像源
# 升级pip
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
# 设置全局镜像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
安装Object Detection API
下载TensorFlow Model Gardedn
里面是一些模型库和支持API的包
GitHub - tensorflow/models: Models and examples built with TensorFlow
使用git clone或直接下载zip然后解压
git clone https://github.com/tensorflow/models.git
Protobuf安装和编译object_detection
前往Releases · protocolbuffers/protobuf · GitHub下载对应版本的protoc,主要是使用里面的脚本
在服务器上解压
unzip protoc-24.3-linux-x86_64.zip -d protoc
设置临时环境变量,根据自己的路径来设置,设置的是protoc/bin
export PATH=$PATH:/home/protoc/bin
进入到路径research进行编译,需要根据自己的目录来
cd /home/fun4/tensorflow/models/research
protoc object_detection/protos/*.proto --python_out=.
安装COCOAPI
pip install pycocotools
安装object_detection
需要在models.research目录下
cp object_detection/packages/tf2/setup.py .
python -m pip install .
测试安装
python object_detection/builders/model_builder_tf2_test.py
from: TensorFlow2.0 学习笔记六 基于object_detection的目标检测一 正确在GPU上使用安装object_detection_shaynerain的博客-CSDN博客