运行环境:
mac 10.13.5
python3.5
tensorflow1.9-cpu
主要步骤:
1、安装 protobuf,版本是3.5.0
https://github.com/protocolbuffers/protobuf/releases
cd prtobuf-3.5.0
./configure
sudo make -j8
make check -j8
sudo make install
如果装错版本,卸载:which protoc rm /usr/local/bin/protoc
查看版本:protoc --version
2、安装bazel
chmod +x bazel-0.15.2-installer-darwin-x86_64.sh
./bazel-0.15.2-installer-darwin-x86_64.sh --user
~/.bashrc: export PATH="$PATH:$HOME/bin":source ~/.bashrc
bazel version
卸载:rm $HOME/.cache/bazel -fr
sudo rm /usr/local/bin/bazel /etc/bazelrc /usr/local/lib/bazel -fr
3、安装Eigen
下载eigen的压缩包 http://bitbucket.org/eigen/eigen/get/3.3.4.tar.bz2,解压,重新命名为eigen3,放到某个路径下
4、Clone Tensorflow源码并进行编译
git clone --recursive https://github.com/tensorflow/tensorflow
cd./tensorflow
git checkout r1.9
sudo ./configure
sudo bazel build --config=opt --config=monolithic //tensorflow:libtensorflow_cc.so
# 如果不加--config=monlithic,编译出来的库会导致cv::imread()为空# 这样导入库时只需导入libtensorflow_cc.so,不再需要libtensorflow_framework.so
sudo mkdir /usr/local/include/tf
sudo cp -r bazel-genfiles/ /usr/local/include/tf/
sudo cp -r tensorflow /usr/local/include/tf/
sudo cp -r third_party /usr/local/include/tf/
sudo cp bazel-bin/tensorflow/libtensorflow_cc.so /usr/local/lib/
sudo cp bazel-bin/tensorflow/libtensorflow_framework.so /usr/local/lib
此处有坑,开始是用的download的下载方式,但是那种方式不确定版本,无法跟protoc版本对上,可能出现各种问题。其实我本来tensorflow用pip安装到了1.13,由于不知道protoc对应的版本,git clone的方式,可以checkout到r1.9,跟预期版本对应,为什么不下1.8?因为安装deepctr包不支持1.8
5、手动编译opencv
因为离线tf代码用到了opencv,需要手动编译opencv
https://www.jianshu.com/p/564c8b352c7f
https://www.jianshu.com/p/1d6ef37138f4
https://blog.csdn.net/orDream/article/details/84311697
opencv开始报了一个花式错CMake Error: The source directory "/usr/local/Cellar/opencv" does not appear to contain CMakeLists.txt,后来不用brew install opencv的方式,而是从git打包下载,解决
cmakelist.txt找不到opencv的包的时候添加
set(OpenCV_DIR /usr/local/opencv/release)
还会遇到一个远程下载ippicv翻墙下载图片包的问题,在第三个链接里有解决方法
6、pipeline演示
见链接https://blog.csdn.net/qq_25109263/article/details/81285952
感谢两位作者:
1、https://blog.csdn.net/qq_25109263/article/details/81285952
2、https://blog.csdn.net/qq_37541097/article/details/86232687
3、https://blog.csdn.net/luanpeng825485697/article/details/81152615
血泪教训:
找一篇版本明确的教程去安装,各个依赖包版本之间都有关系,自己瞎装,如果想通过吐血来减肥的朋友,可以尝试,会遇到花式bug连环攻击