To Top
首页 > 基础知识 > 正文

tf安装

标签:tf安装, tensorflow 安装


目录

装备工作

bazel

jdk1.8

源码安装

clone

git clone https://github.com/tensorflow/tensorflow 

configure

./configure

注意,这里可以配置默认python路径

生成pip_package

仅cpu

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

gpu

bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

生成whl

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

这样,就在/tmp/tensorflow_pkg生成了tensorflow-xxxx-py2-none-any.whl

安装c++库

参考:

https://github.com/hemajun815/tutorial/blob/master/tensorflow/compilling-tensorflow-source-code-into-C++-library-file.md

手动下载依赖库

进入目录:

cd tensorflow/contrib/makefile

执行文件:

sh -x ./build_all_linux.sh
cd -

注意:

必要时修改download_dependencies.sh文件:

  • curl需要支持https(可以升级),比如,我们发现jumbo的curl是符合预期的,那可以在build_all_linux.sh一开头就加上export PATH=~/.jumbo/bin/:$PATH
  • wget加上--no-check-certificate参数,还有--secure-protocol=TLSv1.2参数,当然如果版本不够高就升级wget。如果不好升级可以做如下改动:

wget -P "${tempdir}" "${url}"

改成

curl -Ls "${url}" > "${tempdir}"/xxx

重新configure

cd tensorflow
./configure

编译cc的so

cd tensorflow
bazel build :libtensorflow_cc.so

产出在bazel-bin/tensorflow/libtensorflow_cc.so

拷贝所需头文件

tensorflow_include=./tensorflow_include
mkdir $tensorflow_include
cp -r tensorflow/contrib/makefile/downloads/eigen/Eigen $tensorflow_include/
cp -r tensorflow/contrib/makefile/downloads/eigen/unsupported $tensorflow_include/
cp -r tensorflow/contrib/makefile/gen/protobuf/include/google $tensorflow_include/
cp tensorflow/contrib/makefile/downloads/nsync/public/* $tensorflow_include/
cp -r bazel-genfiles/tensorflow $tensorflow_include/
cp -r tensorflow/cc $tensorflow_include/tensorflow
cp -r tensorflow/core $tensorflow_include/tensorflow
mkdir $tensorflow_include/third_party
cp -r third_party/eigen3 $tensorflow_include/third_party/

拷贝所需lib文件

tensorflow_lib=./tensorflow_lib
mkdir $tensorflow_lib
cp bazel-bin/tensorflow/libtensorflow_*.so $tensorflow_lib

源码安装tf-serving

github地址:https://github.com/tensorflow/serving

如果要clone某个版本,可以直接

git clone -b r1.12 https://github.com/tensorflow/serving.git

如果在docker内安装:

./tools/run_in_docker.sh  bazel build tensorflow_serving/model_servers:tensorflow_model_server

如果在非docker内安装:

bazel build tensorflow_serving/model_servers:tensorflow_model_server

然后我们就发现产出了这么一个bin文件:./bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server


原创文章,转载请注明出处!
本文链接:http://daiwk.github.io/posts/knowledge-tf-install.html
上篇: 单元测试工具
下篇: tf常用函数

comment here..