- 安裝依賴
yum -y install automake libtool libsysfs libxslt-devel libffi libffi-devel python-devel gcc openssl openssl-devel sqlite-devel
pip install six numpy wheel coverage mock
- 安裝CMake
從https://cmake.org/download/選擇最新的版本
wget https://github.com/Kitware/CMake/releases/download/v3.14.0-rc4/cmake-3.14.0-rc4-Linux-x86_64.tar.gz
tar -xvf cmake-3.14.0-rc4-Linux-x86_64.tar.gz
mv cmake-3.14.0-rc4-Linux-x86_64 /usr/local/share/cmake
ln -s /usr/local/share/cmake/bin/ccmake /usr/bin/ccmake
ln -s /usr/local/share/cmake/bin/cmake /usr/bin/cmake
ln -s /usr/local/share/cmake/bin/ctest /usr/bin/ctest
- 安裝java
yum -y install java-1.8.0-openjdk*
- 安裝Bazel
從https://github.com/bazelbuild/bazel/releases選擇合適的版本,具體版本對應關系在https://tensorflow.google.cn/install/source,tensorflow r1.12對應的應是bazel 0.15.0
wget https://github.com/bazelbuild/bazel/releases/download/0.15.0/bazel-0.15.0-installer-linux-x86_64.sh
sh bazel-0.15.0-installer-linux-x86_64.sh --prefix=/usr/local/share/bazel
ln -s /usr/local/share/bazel/bin/bazel /usr/bin/bazel
- 下載TensorFlow
git clone https://github.com/tensorflow/tensorflow
或者
git clone https://jhc888007%40163.com:[password]@github.com/tensorflow/tensorflow
cd tensorflow
git checkout r1.12
./configure
接下來有一系列設置(這步好像不是必須的?),不懂的可以用默認值
- 編譯C庫
cd tensorflow
bazel build :libtensorflow.so
在../bazel-bin/tensorflow/生成libtensorflow.so和libtensorflow_framework.so
- 編譯C++庫
cd tensorflow
bazel build :libtensorflow_cc.so
在../bazel-bin/tensorflow/生成libtensorflow_cc.so和libtensorflow_framework.so
- 安裝依賴
cd contrib/makefile
./build_all_linux.sh
- 安裝Eigen
cd downloads/eigen
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/share/eigen ..
make install
cd /usr/local/include
ln -s ../share/eigen/include/eigen3/Eigen
ln -s ../share/eigen/include/eigen3/unsupported
- 安裝Protobuf(實踐證明對於1.12版本不兼容,行不通)
cd downloads/protobuf
./autogen.sh
./configure --prefix=/usr/local/share/protobuf
make && make install
如果不成功則make clean,再重新make
vim /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/share/protobuf/lib export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/share/protobuf/lib export PATH=$PATH:/usr/local/share/protobuf/bin
export PKG_CONFIG_PATH=/usr/local/share/protobuf/lib/pkgconfig/
- 安裝Protobuf(手動)
在https://github.com/protocolbuffers/protobuf/releases找到合適版本
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.0/protobuf-all-3.6.0.tar.gz
tar -xvf protobuf-all-3.6.0.tar.gz
cd protobuf-3.6.0/
./configure --prefix=/usr/local/share/protobuf
make && make check && make install
vim /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/share/protobuf/lib
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/share/protobuf/lib export PATH=$PATH:/usr/local/share/protobuf/bin
export PKG_CONFIG_PATH=/usr/local/share/protobuf/lib/pkgconfig/
- 如果已經有相同系統環境編譯好的tensorflow包,則只需要安裝依賴環境,然后將已安裝的Eigen拷貝到新機器對應位置,然后將編譯好的tensorflow包拷貝到python安裝目錄lib目錄下
Centos 編譯TensorFlow C/C++庫 libtensorflow.so libtensorflow_framework.so
Centos C/C++庫 libtensorflow.so libtensorflow_framework.so 測試
參考文獻:
https://www.cnblogs.com/hrlnw/p/7007648.html
https://www.jianshu.com/p/d46596558640
https://blog.csdn.net/qq_37674858/article/details/81095101
http://www.cnblogs.com/zjutzz/p/10182099.html
https://blog.csdn.net/u010700335/article/details/69422282/
https://www.cnblogs.com/hrlnw/p/7383951.html
https://blog.csdn.net/qq_29936933/article/details/82107861
https://blog.csdn.net/laowulong350/article/details/79001511
https://tensorflow.google.cn/install/source_windows