Tensorflow - 安装 Tensorflow 目标检测

安装 Tensorflow 目标检测


原文标题:Installation
原文地址:https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md


目录


Installation

依赖项

Tensorflow Object Detection API 依赖于以下的库:

  • Protobuf 3.0.0
  • Python-tk
  • Pillow 1.0
  • lxml
  • tf Slim (which is included in the “tensorflow/models/research/” checkout)
  • Jupyter notebook
  • Matplotlib
  • Tensorflow
  • Cython
  • contextlib2
  • cocoapi

有关安装 Tensorflow 的详细步骤, 见 Tensorflow installation instructions. 一个具有代表性的用户安装可使用以下命令:

# For CPU
pip install tensorflow
# For GPU
pip install tensorflow-gpu

剩余的库在 Ubuntu 16.04 中可以通过使用 apt-get 安装:

sudo apt-get install protobuf-compiler python-pil python-lxml python-tk
pip install --user Cython
pip install --user contextlib2
pip install --user jupyter
pip install --user matplotlib

或者,用户可以通过 pip 安装:

pip install --user Cython
pip install --user contextlib2
pip install --user pillow
pip install --user lxml
pip install --user jupyter
pip install --user matplotlib

注意: 有时 “sudo apt-get install protobuf-compiler” 会为你安装 Protobuf 3+ 版本,但一些用户在使用 3.5 版本时,会出现一些问题。如果你出现了问题,请尝试 手动 安装.

安装 COCO API

下载 cocoapi ,然后复制 pycocotools 文件夹到 tensorflow/models/research 文件夹。默认使用基于 Pascal VOC 的评价指标; 如果你对使用 COCO 评价指标感兴趣:使用 COCO 目标检测(object detection)指标,请添加metrics_set: "coco_detection_metrics"到配置文件eval_config消息中;使用 COCO 实例分割(instance segmentation)指标,请添加metrics_set: "coco_mask_metrics"到配置文件eval_config消息中。

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

编译 Protobuf

Tensorflow Object Detection API 使用 Protobufs 来控制模型与训练参数。在使用框架之前,Protobuf 库必须被编译。这可以在 tensorflow/models/research/ 文件夹下运行命令:

# From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.

注意:如果你在编译过程中遇到了错误,可能是你使用了不兼容的 protobuf compiler 。 如果是这样,请手动安装。

protobuf-compiler 的手动安装与使用

下载和安装 protoc 的 3.0 release 版本,然后解压文件。

# From tensorflow/models/research/
wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip
unzip protobuf.zip

再次运行编译程序,不过要使用刚刚下载的版本的 protoc 。

# From tensorflow/models/research/
./bin/protoc object_detection/protos/*.proto --python_out=.

将库添加进 PYTHONPATH

当在本地运行时,tensorflow/models/research/ 和 slim 文件夹需要加入 PYTHONPATH 。这可以在 tensorflow/models/research/ 文件夹下运行下列命令来完成:

# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

注意:这个命令需要你在每次运行终端时都使用一次。如果你想避免每次都手动执行,你可以添加到 ~/.bashrc 文件中的最底端,用你系统中的 tensorflow/models/research 绝对路径替换 `pwd` 。

测试安装

你可以运行以下命令来测试 Tensoflow Object Detection 是否安装正确:

python object_detection/builders/model_builder_test.py

猜你喜欢

转载自blog.csdn.net/darkrabbit/article/details/81295025