TensorFlow是什么

时间:2020-11-13 08:20:53

简介

TensorFlow是谷歌的第二代机器学习系统,它是基于数据流编程的符号数学系统,被广泛应用于各类机器学习算法的编程实现。

编译配置流程

1. 配置编译环境

1)修改ubuntu的镜像源,参考https://bbs.huaweicloud.com/forum/thread-22424-1-1.html。

cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
wget -O /etc/apt/sources.list https://mirrors.huaweicloud.com/repository/conf/Ubuntu-Ports-bionic.list
apt-get update

2)安装依赖包。

apt-get install zlib1g-dev zlib1g python3-numpy libstdc++* python3-pip zip -y
pip3 install numpy
pip3 install wheel

3)先清除掉系统自带的JDK。

Tensorflow 1.4.1依赖的JDK版本不高于jdk-8u151,先清除掉系统自带的JDK。

apt-get --purge remove openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless -y

4)下载和解压jdk-8u151。

cd /usr/local/src
wget https://repo.huaweicloud.com/java/jdk/8u151-b12/jdk-8u151-linux-arm64-vfp-hflt.tar.gz
tar -zxvf jdk-8u151-linux-arm64-vfp-hflt.tar.gz

5)配置java环境变量。

vi /etc/profile

增加如下内容,并保存退出。

export JAVA_HOME=/usr/local/src/jdk1.8.0_151
export JRE_HOME=/usr/local/src/jdk1.8.0_151/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

6)使环境变量生效。

source /etc/profile

7)安装bazel。

a.下载和解压bazel。

cd /usr/local/src
wget https://github.com/bazelbuild/bazel/releases/download/0.5.4/bazel-0.5.4-dist.zip
mkdir /usr/local/src/bazel -p
cd /usr/local/src/bazel
unzip ../bazel-0.5.4-dist.zip

b.编译bazel。

cd /usr/local/src/bazel
bash compile.sh

c.配置bazel。

将可执行文件复制到“/usr/bin”目录下。

cp /usr/local/src/bazel/output/bazel  /usr/bin

2.获取源码

获取“TensorFlow-1.4.1”源码包。

cd /usr/local/src
wget https://github.com/tensorflow/tensorflow/archive/v1.4.1.tar.gz

3.编译和安装

1)解压软件包。

cd /usr/local/src
tar -zxvf v1.4.1.tar.gz

2)进入Hue的安装目录。

cd tensorflow-1.4.1/

3)配置TensorFlow。

./configure

具体配置如下

Extracting Bazel installation...
You have bazel 0.5.4- (@non-git) installed.
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3
Found possible Python library paths:
/usr/lib/python3/dist-packages
/usr/local/lib/python3.6/dist-packages
Please input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages]
Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: Y
jemalloc as malloc support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: n
No Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: n
No Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: n
No Amazon S3 File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: N
No XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: N
No GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: N
No VERBS support will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL support? [y/N]: N
No OpenCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: N
No CUDA support will be enabled for TensorFlow.
Do you wish to build TensorFlow with MPI support? [y/N]: N
No MPI support will be enabled for TensorFlow.
Please note that MKL on MacOS or windows is still not supported.
If you would like to use a local MKL instead of downloading, please set the environment variable "TF_MKL_ROOT" every time bef
ore build.
Configuration finished

4)编译TensorFlow。

cd /usr/local/src/tensorflow-1.4.1/
bazel build //tensorflow/tools/pip_package:build_pip_package

5)安装TensorFlow。

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
cd /tmp/tensorflow_pkg
pip3 install tensorflow-1.4.1-cp36-cp36m-linux_aarch64.whl

4.运行和验证

测试TensorFlow,中间的提示请忽略。

python3

参照如下输入测试TensorFlow

>>> import tensorflow as tf
>>> arr_a = tf.constant([3.0,4.0],name ="arr_a")
>>> arr_b = tf.constant([3.0,4.0],name ="arr_b")
>>> sess=tf.Session()
>>> arr_res=arr_a + arr_b
>>> sess.run(arr_res)
array([6., 8.], dtype=float32)

上一篇: Httperf是什么

下一篇: 什么是GATK?

猜你喜欢