為了編譯支援tensorflow 框架的Face detector的AP,其中使用到tensorflow c/c++ api,所以需要下載原始碼編譯出libtensorflow.so檔來使用,接下來就是介紹整個編譯環境的過程。

1. 簡介:
tensorflow提供了python, c/c++的API,我們現在的應用用到c/c++版本,所以需要編譯出library來使用,在編譯library時,必需使用bazel及protobuf及eigen工具,應將其工具準備好。
FaceDetector AP 源碼: https://github.com/OAID/FaceDetection

2. 編譯環境及工具版本
   a. Ubuntu 18.04
   b. Python 3.6
   c. Bazel 0.26 -  https://github.com/bazelbuild/bazel/releases/tag/0.26.0
   d. TensorFlow - https://github.com/tensorflow/tensorflow
   e. protobuf 3.8.0 - https://github.com/protocolbuffers/protobuf/archive/v3.8.0.tar.gz
   f. eigen3
   g. JDK
以上這些套裝工具的版本都是有配對的,若版號不同,或許在編譯過程中會出現版本不相容的狀況發生,這現象很不好處理,最好版本還是一致會較好,像protocbuf的版本必須和你編譯的tensorflow版本的protocbuf相同,如果不一樣,後面編譯你自己的代碼時是跑不起來的; 

2-1. 安裝Eigen,參考網址:  https://blog.csdn.net/xiat5/article/details/79162617

a. 安裝:
$ sudo apt-get install libeigen3-dev
b. 調整,默認安裝路徑:/usr/include/eigen3
$ cd /usr/include/eigen3
$ ls

$ Eigen signature_of_eigen3_matrix_library unsupported
c. 需要執行命令,将Eigen文件夾放在/usr/include 下面
$ sudo cp Eigen/ .. -R
d. 編寫文件進行測試
$ vi myeigen.c
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;

int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
}
e. 編譯。
$ g++ myeigen.c -o myeigen
e. 執行
$ ./myeigen
f. 结果。
$ 3 -1 2.5 1.5

2-2. 編譯及安裝bazel
bazel是google用於建構項目的工具,只要用在建構google的軟體,tensorflow需要用到。在ubuntu18.04上,若使用apt-get安裝是無法成功的,需要下載源碼進行編譯安裝。在編譯tensorflow的過程中吃了不少bazel版本的不相容錯誤,所以最後確定版為0.26。在裝bazel之前需要安裝jdk。
參考網址:  https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu

a.  安裝需要的套件,有 pkg-configzipg++zlib1g-devunzip,python3.
    $ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3
b. 下載源碼,bazel-0.26.0-installer-linux-x86_64.sh
    $ git clone https://github.com/bazelbuild/bazel/releases/tag/0.26.0
b. 執行
    $ chmod +x bazel-0.26.0-installer-linux-x86_64.sh
    $ ./bazel-0.26.0-installer-linux-x86_64.sh --user
The --user flag installs Bazel to the $HOME/bin directory on your system and sets the .bazelrc path to $HOME/.bazelrc.
d. 設定環境變數
   $ export PATH="$PATH:$HOME/bin"

2-3 安裝protobuf,參考網址:  https://github.com/protocolbuffers/protobuf/blob/master/src/README.md ,
請在tensorflow德資料夾下找到workspace.bzl,即可查詢到protobuf所需要的版本。

a. 下載源碼
$ git clone https://github.com/protocolbuffers/protobuf/archive/v3.8.0.tar.gz
$ cd protobuf
$ ./autogen.sh
b.編譯源碼
$ ./configure
$ make
$ make check
$ make install

$ sudo ldconfig # refresh shared library cache

<<未完待續>>
 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 ^_^ 的頭像
    ^_^

    一切的安排,都是最好的安排

    ^_^ 發表在 痞客邦 留言(0) 人氣()