< >
Home » TX2入门教程软件篇 » TX2入门教程软件篇-安装TensorFlow(1.2)+python3.5(jetpack3.0)

TX2入门教程软件篇-安装TensorFlow(1.2)+python3.5(jetpack3.0)

TX2入门教程软件篇-安装TensorFlow(1.2)+python3.5

说明:

  • 介绍如何在TX2上安装TensorFlow1.2版本

环境:

  • jetpack 3.0 full安装
  • cudnn 5.1.10
  • cuda 8.0
  • python 3.5.2

安装:

  • 安装依赖
#install dependencies
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer -y
sudo apt-get install zip unzip autoconf automake libtool curl zlib1g-dev maven -y
sudo apt install python3-numpy python3-dev python3-pip python3-wheel
 
  • 安装bazel
bazel_version=0.5.1
wget https://github.com/bazelbuild/bazel/releases/download/$bazel_version/bazel-$bazel_version-dist.zip
unzip bazel-$bazel_version-dist.zip -d bazel-dist
sudo chmod -R ug+rwx bazel-dist
cd bazel-dist
./compile.sh 
sudo cp output/bazel /usr/local/bin
 
  • 安装tensorflow
git clone --recursive https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v1.2.0
  • 修改tensorflow/workspace.bzl,更改为如下:
  native.new_http_archive(
      name = "eigen_archive",
      urls = [
          "http://mirror.bazel.build/bitbucket.org/eigen/eigen/get/d781c1de9834.tar.gz",
          "https://bitbucket.org/eigen/eigen/get/d781c1de9834.tar.gz",
      ],
      sha256 = "a34b208da6ec18fa8da963369e166e4a368612c14d956dd2f9d7072904675d9b",
      strip_prefix = "eigen-eigen-d781c1de9834",
      build_file = str(Label("//third_party:eigen.BUILD")),
  )
  • 配置编译变量
export PYTHON_BIN_PATH=$(which python3)
# No Google Cloud Platform support
export TF_NEED_GCP=0
# No Hadoop file system support
export TF_NEED_HDFS=0
# Use CUDA
export TF_NEED_CUDA=1
# Setup gcc ; just use the default
export GCC_HOST_COMPILER_PATH=$(which gcc)
# TF CUDA Version 
export TF_CUDA_VERSION=8.0
# CUDA path
export CUDA_TOOLKIT_PATH=/usr/local/cuda
# cuDNN
export TF_CUDNN_VERSION=5.1.10
export CUDNN_INSTALL_PATH=/usr/lib/aarch64-linux-gnu
# CUDA compute capability
export TF_CUDA_COMPUTE_CAPABILITIES=6.2
export CC_OPT_FLAGS=-march=native
export TF_NEED_JEMALLOC=1
export TF_NEED_OPENCL=0
export TF_ENABLE_XLA=1
 
  • 编译
./configure
 
  • 生成
bazel build -c opt --verbose_failures --config=cuda //tensorflow/tools/pip_package:build_pip_package
  • 进行打包
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
  • 移动到跟目录
mv /tmp/tensorflow_pkg/tensorflow-1.2.0*-linux_aarch64.whl ..
  • 安装whl文件,可能提示版本问题,参考错误提示修改
sudo pip install tensorflow-1.2.0-cp35-cp35m-linux_aarch64.whl
  • 效果:
ubuntu@tegra-ubuntu:~$ pip install tensorflow-1.2.0-cp35-cp35m-linux_aarch64.whl 
Processing ./tensorflow-1.2.0-cp35-cp35m-linux_aarch64.whl
Collecting numpy>=1.11.0 (from tensorflow==1.2.0)
  Downloading numpy-1.13.1.zip (5.0MB)
    100% |████████████████████████████████| 5.0MB 131kB/s 
Collecting werkzeug>=0.11.10 (from tensorflow==1.2.0)
  Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)
    100% |████████████████████████████████| 317kB 658kB/s 
Collecting six>=1.10.0 (from tensorflow==1.2.0)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting protobuf>=3.2.0 (from tensorflow==1.2.0)
  Downloading protobuf-3.4.0-py2.py3-none-any.whl (375kB)
    100% |████████████████████████████████| 378kB 713kB/s 
Collecting backports.weakref==1.0rc1 (from tensorflow==1.2.0)
  Downloading backports.weakref-1.0rc1-py3-none-any.whl
Collecting html5lib==0.9999999 (from tensorflow==1.2.0)
  Downloading html5lib-0.9999999.tar.gz (889kB)
    100% |████████████████████████████████| 890kB 414kB/s 
Collecting markdown==2.2.0 (from tensorflow==1.2.0)
  Downloading Markdown-2.2.0.tar.gz (236kB)
    100% |████████████████████████████████| 245kB 775kB/s 
Collecting wheel>=0.26 (from tensorflow==1.2.0)

测试:

  • 脚本:
vim test_tensorflow.py
  • 内容:
#!/usr/bin/env python 

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
  • 设置权限:
chmod +x test_tensorflow.py
  • 执行:
python test_tensorflow.py
  • 效果:
ubuntu@tegra-ubuntu:~$ python test_tensorflow.py 
2017-08-22 19:03:24.966806: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:879] could not open file to read NUMA node: /sys/bus/pci/devices/0000:00:00.0/numa_node
Your kernel may have been built without NUMA support.
2017-08-22 19:03:24.966928: I tensorflow/core/common_runtime/gpu/gpu_device.cc:940] Found device 0 with properties: 
name: GP10B
major: 6 minor: 2 memoryClockRate (GHz) 1.3005
pciBusID 0000:00:00.0
Total memory: 7.67GiB
Free memory: 3.06GiB
2017-08-22 19:03:24.966987: I tensorflow/core/common_runtime/gpu/gpu_device.cc:961] DMA: 0 
2017-08-22 19:03:24.967016: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   Y 
2017-08-22 19:03:24.967043: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GP10B, pci bus id: 0000:00:00.0)
2017-08-22 19:03:24.967077: I tensorflow/core/common_runtime/gpu/gpu_device.cc:642] Could not identify NUMA node of /job:localhost/replica:0/task:0/gpu:0, defaulting to 0.  Your kernel may not have been built with NUMA support.
2017-08-22 19:03:26.049310: I tensorflow/compiler/xla/service/platform_util.cc:58] platform CUDA present with 1 visible devices
2017-08-22 19:03:26.049373: I tensorflow/compiler/xla/service/platform_util.cc:58] platform Host present with 4 visible devices
2017-08-22 19:03:26.050126: I tensorflow/compiler/xla/service/service.cc:198] XLA service 0x29d7000 executing computations on platform Host. Devices:
2017-08-22 19:03:26.050180: I tensorflow/compiler/xla/service/service.cc:206]   StreamExecutor device (0): <undefined>, <undefined>
2017-08-22 19:03:26.051089: I tensorflow/compiler/xla/service/platform_util.cc:58] platform CUDA present with 1 visible devices
2017-08-22 19:03:26.051134: I tensorflow/compiler/xla/service/platform_util.cc:58] platform Host present with 4 visible devices
2017-08-22 19:03:26.051829: I tensorflow/compiler/xla/service/service.cc:198] XLA service 0x2a26f40 executing computations on platform CUDA. Devices:
2017-08-22 19:03:26.051876: I tensorflow/compiler/xla/service/service.cc:206]   StreamExecutor device (0): GP10B, Compute Capability 6.2
b'Hello, TensorFlow!'

问题:

  • 1.安装wheel错误:
tensorflow-1.2.0-cp35-cp35m-linux_aarch64.whl is not a supported wheel on this platform.
  • 解决:修改python默认指定python3.5,TX2默认python是python2.7
lrwxrwxrwx 1 root root       9 Dec 10  2015 python -> python2.7
lrwxrwxrwx 1 root root       9 Dec 10  2015 python2 -> python2.7
-rwxr-xr-x 1 root root 3119496 Nov 19  2016 python2.7
lrwxrwxrwx 1 root root      34 Nov 19  2016 python2.7-config -> aarch64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root      16 Dec 10  2015 python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Mar 23  2016 python3 -> python3.5
-rwxr-xr-x 2 root root 3953904 Nov 18  2016 python3.5
  • 修改后:
lrwxrwxrwx 1 root root       9 Dec 10  2015 python -> python3.5
lrwxrwxrwx 1 root root       9 Dec 10  2015 python2 -> python2.7
-rwxr-xr-x 1 root root 3119496 Nov 19  2016 python2.7
lrwxrwxrwx 1 root root      34 Nov 19  2016 python2.7-config -> aarch64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root      16 Dec 10  2015 python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Mar 23  2016 python3 -> python3.5
-rwxr-xr-x 2 root root 3953904 Nov 18  2016 python3.5

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: tx2入门教程软件篇