欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

搭建TensorFlow环境

程序员文章站 2022-03-29 19:29:26
...

TensorFlow GitHub

克隆TensorFlow仓库

$ sudo apt install git
$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git

安装Bazel

Getting Started with Bazel
Ubuntu Linux
Compile Bazel from source
GitHub releases page
下载bazel-0.11.1-dist.zip,如果下载不下来,传送门

$ sudo apt install openjdk-8-jdk
$ cd bazel-0.11.1-dist/
$ ./compile.sh

将执行路径output/bazel添加到$PATH环境变量中

$ vi ~/.bashrc
export PATH=$PATH:/home/zhnd/bazel-0.11.1-dist/output
$ source ~/.bashrc

配置TensorFlow

$ cd tensorflow/
$ ./configure

创建pip包并安装

$ sudo apt install python-pip
$ sudo apt install python-numpy
$ cd tensorflow/
$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# /tmp/tensorflow_pkg目录下生成xxx.whl文件(e.g. tensorflow-1.7.0rc1-cp27-cp27mu-linux_x86_64.whl)
$ pip install /tmp/tensorflow_pkg/xxx.whl

Try your first TensorFlow program

$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)
'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a + b)
42
>>> sess.close()




参考:TensorFlow中文社区