The value of knowledge lies not in possession, but in share.

0%

TensorFlow Object detection API教程之一:TensorFlow及其Object detection API安装

之前一直在Caffe平台做object detection,后面查阅相关资料时,经常看到TensorFlow下的object detection API,怀着好奇心了解了下,发现效果很不错,总体而言比Caffe下要简单些。

Google niubility !

TensorFlow Object detection API 教程系列:

安装TensorFlow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 安装TensorFlow
pip install tensorflow # For CPU
pip install tensorflow-gpu # For GPU

# 若安装不同版本的TensorFlow
# pip install tensorflow==1.4.0
# pip install tensorflow-gpu==1.4.0
# 卸载TensorFlow
# pip uninstall tensorflow

# 验证TensorFlow是否安装成功
# 输出Hello, TensorFlow! 则代表安装成功。
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))

安装TensorFlow Object Detection API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 安装依赖项
sudo apt-get install protobuf-compiler python-pil python-lxml
sudo pip install jupyter
sudo pip install matplotlib

# 下载TensorFlow Object Detection API
mkdir ~/tensorflow
cd ~/tensorflow
git clone https://github.com/tensorflow/models.git

# 编译protobuf
# 进入object_detection所在目录
# 譬如:cd ~/tensorflow/models/research/
# 编译成功时,界面无任何显示
protoc object_detection/protos/*.proto --python_out=.

# 添加环境变量
# 1.进入object_detection所在目录
# 譬如:cd ~/tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
# 这条命令在新打开的终端中需要重新执行一次才会在新终端中生效
# 2.添加到~/.bashrc
gedit ~/.bashrc
# 将下面命令添加到最后,注意'pwd'更换为object_detection的路径
# export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
# 进入object_detection所在目录,在终端输入pwd查询
# 例如我的
export PYTHONPATH=$PYTHONPATH:/root/tensorflow/models/research:/root/tensorflow/models/research/slim


# Test
python object_detection/builders/model_builder_test.py
# 成功则显示如下:
.......
----------------------------------------------------------------------
Ran 7 tests in 0.026s

OK

Debugs

1
2
3
4
5
6
# Bug
illegal instruction (sore dumped)

# Debug
pip uninstall tensorflow
pip install tensorflow==1.5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Bug
object_detection/protos/ssd.proto:11:3: Expected "required", "optional", or "repeated".

# Debug
# 使用高版本protoc
#download protoc 3.3
mkdir protoc_3.3
cd protoc_3.3
wget https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip
chmod 775 protoc-3.3.0-linux-x86_64.zip
unzip protoc-3.3.0-linux-x86_64.zip
#compile proto file
cd /usr/local/lib/python2.7/dist-packages/tensorflow/models/
~/protoc_3.3/bin/protoc object_detection/protos/*.proto --python_out=.

🍭支持一根棒棒糖吧!