Note: There is an updated article for installing TensorFlow 1.3 on the Jetson TX2 running L4T 28.1. The repository for these scripts has been updated. Please make sure to checkout the tagged version for L4T 27.1 in this article.
In this article, we will work through installing TensorFlow v1.0.1 on the Jetson TX2. Looky here:
Background
TensorFlow is one of the major deep learning systems. Created at Google, it is an open-source software library for machine intelligence. The Jetson TX2 ships with TensorRT, which is the run time for TensorFlow. TensorRT is what is called an “Inference Engine“, the idea being that large machine learning systems can train models which are then transferred over and “run” on the Jetson.
However, some people would like to use the entire TensorFlow system on a Jetson. This has been difficult for a few reasons. The first reason is that TensorFlow binaries aren’t generally available for ARM based processors like the Tegra TX2. The second reason is that actually compiling TensorFlow takes a larger amount of system resources than is normally available on the Jetson TX2. The third reason is that TensorFlow itself is rapidly changing (it’s only a year old), and the experience has been a little like building on quicksand.
In this article, we’ll go over the steps to build TensorFlow v1.0.1 on the Jetson TX2. This will take about three hour and a half hours to build.
Note: Please read through this article before starting installation. This is not a simple installation, you may want to tailor it to your needs.
Preparation
This article assumes that Jetson 3.0 is used to flash the Jetson TX2. At a minimum, install:
- L4T 27.1 an Ubuntu 16.04 64-bit variant (aarch64)
- CUDA 8.0
- cuDNN 5.1.10
TensorFlow will use CUDA and cuDNN in this build.
In order to get TensorFlow to compile on the Jetson TX2, a swap file is needed for virtual memory. Also, a good amount of disk space ( > 6 GB ) is needed to actually build the program. If you’re unfamiliar with how to set the Jetson TX2 up like that, the procedure is similar to that as described in the article: Jetson TX1 Swap File and Development Preparation.
There is a repository on the JetsonHacks account on Github named installTensorFlowTX2. Clone the repository and switch over to that directory.
$ git clone https://github.com/jetsonhacks/installTensorFlowTX2
$ cd installTensorFlowTX2
$ git checkout vL4T27.1TF1.0
Prerequisites
There is a convenience script which will install the required prerequisites such as Java and Bazel. The script also patches the source files appropriately for ARM 64.
$ ./installPrerequisites.sh
From the video installation of the prerequisites takes a little over 30 minutes, but will depend on your internet connection speed.
Building TensorFlow
First, clone the TensorFlow repository and patch for Arm 64 operation:
$ ./cloneTensorFlow.sh
then setup the TensorFlow environment variables. This is a semi-automated way to run the TensorFlow configure.sh file. You should look through this script and change it according to your needs. Note that most of the library locations are configured in this script. The library locations are determined by the JetPack installation.
$ ./setTensorFlowEV.sh
We’re now ready to build TensorFlow:
$ ./buildTensorFlow.sh
This will take a couple of hours. After TensorFlow is finished building, we package it into a ‘wheel’ file:
$ ./packageTensorFlow.sh
The wheel file will be in the $HOME directory, tensorflow-1.0.1-cp27-cp27mu-linux_aarch64.whl
Installation
Pip can be used to install the wheel file:
$ pip install $HOME/tensorflow-1.0.1-cp27-cp27mu-linux_aarch64.whl
Validation
You can go through the procedure on the TensorFlow installation page: Tensorflow: Validate your installation
Validate your installation Validate your TensorFlow installation by doing the following:
Start a terminal.
Change directory (cd) to any directory on your system other than the tensorflow subdirectory from which you invoked the configure command.
Invoke python:
$ python
Enter the following short program inside the python interactive shell:
>>> import tensorflow as tf
>>> hello = tf.constant(‘Hello, TensorFlow!’)
>>> sess = tf.Session()
>>> print(sess.run(hello))
If the Python program outputs the following, then the installation is successful and you can begin writing TensorFlow programs.
Hello, TensorFlow!”
Conclusion
So there you have it. Building TensorFlow is quite a demanding task, but hopefully some of these scripts may make the job a little bit simpler.
21 Responses
In your tensorflow patch script, the first patch fails. I believe the BUILD file has been updated since r0.11 and it looks like you are using the same or similar patch file. Though this does not seem to damage the rest of the build.
Visible at 3:31 in the video.
Good catch! Looking back at my notes, I had marked that I needed to remove it, but with there’s three hours between builds I must have forgot about it. As you noted, the patch doesn’t do anything, so everything should work. I also have a note that questions the two patches that followed. They are needed on the TX1. I wasn’t sure if it applied for the TX2, so I just left them in. Thanks for finding this, and thanks for reading!
Hi there,
Thanks for the detailed tutorial! I’m a bit of a noob with all this, so your video is very helpful! I’m running into an error when running packageTensorFlow.sh. Here’s the error:
can’t copy ‘tensorflow/contrib/image/ops/gen_image_ops.py’: doesn’t exist or not a regular file
Any thoughts on what might be the issue? I looked in that directory and the file indeed isn’t there.
Thanks again!
Matt
It sounds like your build is incomplete. The referenced file is generated during the build process. You can try the ‘buildTensorFlow.sh’ script again and look for any issues that may have cropped up. Thanks for reading!
hi can i use this for jetson tx1 kit
The short answer is no, there’s currently an issue with the NVCC for TF v1.0
Here’s an installation article for the TX1 for TF v0.11 https://jetsonhacks.com/2017/01/15/tensorflow-build-update-jetson-tx1/
Thanks for reading!
I have currently installed TF v0.11 and wish to upgrade to TF v1.0 on my jetson TX1. Is the issue with NVCC resolved for TF v1.0 for the Jetson TX1?
I have not tried it yet. You should ask on the NVIDIA Jetson TX1 forum:https://devtalk.nvidia.com/default/board/164/jetson-tx1/
to see if others have tried.
Have you considered doing a cross-build instead? A nice x64 linux server would probably build a lot faster!
I leave that to the professionals. Thanks for reading!
First of all, Thanks for the instructions. With few modifications to scripts, manage to install TensorFlow for Python3 on Jetson TX2. Updated scripts are available at https://github.com/ramkumarkoppu/installTensorFlowTX2 if you wish to use Tensorflow with Python3.
You’re welcome. You’re updated scripts should prove useful to people interested in Python 3. Thanks for sharing!
Do you know how to install Tensorflow on a Jetson TK1?
I don’t. You can Google it and find other people have got it to run. Thanks for watching!
I get the following error when running ./installPrerequisites.sh
cannot stat output/bazel
I’m using Jetson TX2 with Jetpack 3.1 as mentioned in the preperation section of this blog.
ERROR: Could not build Bazel
cp: cannot stat ‘output/bazel’: No such file or directory
The Bazel build does not succeed due to an issue with the Java package. Within the last few days the Java has archived version 141, which leads to the above error. I haven’t figured out how to fix it yet.
Is there a latest working procedure to bring-up TensorFlow on Jetson TX2 elsewhere?
I do not know what you are asking. If you are installing TensorFlow from source, you will need to manually install JAVA that matches the bazel criteria. Unless you are modifying the TensorFlow source code itself, you are better off installing .whl files. are several available, including: https://github.com/jetsonhacks/installTensorFlowJetsonTX
Hello ! Thank you very much for this article. Is there an update for JetPack 3.2?
L4T R28.2
CUDA 9.0
cuDNN 7.0.5 RC
Or should I use a mechanism to install TensorFlow? (Virtualenv/Anaconda)
Thank you in advance for you help!
Valentin
https://jetsonhacks.com/2018/03/26/build-tensorflow-on-nvidia-jetson-tx-development-kits/
You should install a whl file and not install from source.