Tensorflow Object detection Api的安装

这里首先来说一下tensorflow object detection api的安装。
1、安装Tensorflow
建议使用anaconda进行安装,这样可以很方便的调整tensorflow的版本:以下是一些参考资料
在 Windows 平台安装 NVIDIA GPU 加速的 TensorFlow
使用 Anaconda 进行安装Tensorflow
TensorFlow安装 - Anaconda方式

2、下载官方的代码Tensorflow Models

可以选择master分支

git clone https://github.com/tensorflow/models.git

也可以选择其他分支进行下载。之所以这么说,是因为有大神给出了在TX2上加速ssd-mobilenet-v1的方法,但是只支持在r1.5分支下的models,因为tensorflow models不断更新,将一些网络节点的名字给变掉了,所以要注意一下。
现在的master分支中,object detection开始特定支持Google TPU训练数据,之前的版本(起码我在5.22号 git下来的代码)是没有对TPU的指定支持的。

3、安装COCO APi
这个API(官方链接)主要在模型的eval中要用到。这个后期再说。
ubuntu&mac下:

git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
make
cp -r pycocotools ./models/research/

其实就是在PythonAPI目录下运行

python setup.py

如果你遇到类似no module named _mask?的问题,你可以尝试如下代码或者参考window上的一个解决方案

python setup.py build
python setup.py install

扫描二维码关注公众号,回复: 2919269 查看本文章

这里需要说明一下,在之前版本的object detection的安装中,coco api是不必须安装的,正如tensorflow自己的文档所写的:

Download the cocoapi and copy the pycocotools subfolder to the tensorflow/models/research directory if you are interested in using COCO evaluation metrics. The default metrics are based on those used in Pascal VOC evaluation. To use the COCO object detection metrics add metrics_set: “coco_detection_metrics” to the eval_config message in the config file. To use the COCO instance segmentation metrics add metrics_set: “coco_mask_metrics” to the eval_config message in the config file.

那个时候,在object detection目录中的evaluator.py中,是默认采用pascal_voc_detection_metrics. 但是,我观察到现在改为了eval_util.py文件,而这个文件中预设的metric就是coco数据集的metric:

EVAL_DEFAULT_METRIC = ‘coco_detection_metrics’

所以,总的来说,现在必须安装coco api了,除非你不用现在的分支,而是git 历史分支,又或者你不对你的模型进行eval(当然,这是不科学的)。

4、编译protobuf

Tensorflow Object Detection API使用Protobufs来配置模型和训练参数。在使用框架之前,必须编译Protobuf库。这应该通过在models/目录运行以下命令来完成:

protoc object_detection/protos/*.proto –python_out=.

5、设置python搜索路径

(1)永久性修改:
1)打开终端,输入

open ./bash_profile

2)将打开的文件的最后一行进行如下替换(记得把pwd换成models在自己的电脑中的文件路径)

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

3)再在终端运行如下代码

source ~/.bash_profile

(2)或者暂时性修改

set PYTHONPATH=pwd;pwd\research;pwd\research\slim

这里的pwd是需要你自己修改为你自己电脑上的models的路径的,不要直接复制

如果之后你还是遇到类似 No module named ‘object_detection’ 的问题,你可以尝试:
在research 目录下运行:

python setup.py build
python setup.py install

或者参考这里的讨论.

6、安装完毕:测试一下

python object_detection / builders / model_builder_test.py

输出OK表示设置完成。

猜你喜欢

转载自blog.csdn.net/ljyt2/article/details/82143904