本文介绍 TensorFlow Object Detection API 2

TensorFlow Object Detection API 2

This article was original written by Jin Tian, welcome re-post, first come with https://jinfagang.github.io . but please keep this copyright info, thanks, any question could be asked via wechat: jintianiloveu

TensorFlow C++ 编译

接下来得编译一下tensorflow的c++的动态链接库了。然后将object detection的这个api,用从c++去预测。最终的目的是把加速加速到一个合理的水平。二话不说,先把C++链接库先编译一下。

1
2
3
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install -y bazel

然后clone tensorflow源代码,进入进行一下configure:

1
2
./configure
# balabla一大堆

编译一行代码:

1
bazel build --config=opt --config=cuda //tensorflow:libtensorflow_cc.so

如果没有什么问题,那么就编译成功了:

1
INFO: Build completed successfully, 3621 total actions

编译完成之后,我们还需要把TensorFlow拷贝到系统路径下,这样C++程序才能正确找到它。

1
2
3
4
5
6
cd /path/to/tensorflow/root
sudo mkdir /usr/local/include/tensorflow
sudo cp -r bazel-genfiles /usr/local/include/tensorflow/
sudo cp -r tensorflow /usr/local/include/tensorflow/
sudo cp -r third_party /usr/local/include/tensorflow/
sudo cp -r bazel-bin/tensorflow/libtensorflow_cc.so /usr/local/lib

使用TensorFlow C++ API进行推理

成功编译了TensorFlow的C++ 链接库之后,我们需要写一个C++的推理程序,同时把动态链接库找到,这里面就会遇到两个问题,一个是找到链接库,另外一个C++接口,先把第一个问题解决吧:

1
2