本文內容安排如下:
- 刷機
- 刷機完成后的操作
- 安裝TensorFlow1.0.1
- install TensorFlow v1.2.1
刷機
刷機的目的是把Ubuntu操作系統和JetPack SDK安裝到Jetson TX2上。刷機的操作按照官方教程即可,比較容易。這個過程中有一點需要注意:Jetson TX2和宿主機Host必須連接在同一個路由器之下。Host會先把操作系統刷到TX2上,這一步是通過數據線連接的方式完成,然后使用SSH的方式安裝Host上的SDK到TX2,所以Host和TX2需要連接在同一個路由器下,方便Host找到TX2的ip地址。
刷機開始的時候需要將TX2設置到RECOVRY MODE,設置方法在安裝過程中會給出提示,請仔細閱讀該提示即可完成操作。
另外一個問題是關于從網絡下載安裝文件到Host上過程中,因為我們公司網絡為內網環境,無法連接到網絡下載源,從而導致下載失敗。如果遇到這種情況,更換網絡環境就可以了。
刷機完成后的操作
這一部分主要是卸載Ubuntu里面一些不必要的軟件,騰出更多磁盤空間。具體請參照jetsonHacks的postFlashTX1。我只是卸載了Libre Office,因為在以后的開發過程中不會用到這些。
另外,上面的教程也提供了添加swap file的腳本。添加swap file是為了在硬盤上創建虛擬內存,給編譯像TensorFlow這種大型的項目提供足夠的內存。例如TX2的真實內存只有8G,編譯TF也需要至少8G的內存,所以有必要創建虛擬內存空間。
添加虛擬內存空間的操作,我直接參考了“How to install TensorFlow on the NVIDIA Jetson TX2?”中的Step 4:Create a Swap File,在磁盤上創建了8G的虛擬空間。
1. 創建8G大小的swapfile
fallocate -l 8G swapfile
2. 更改swapfile的權限
chmod 600 swapfile
3. 創建swap區
mkswap swapfile
4. 激活swap區
sudo swapon swapfile
5. 確認swap區在用
swapon -s
執行第五步,輸出中會有新建立的虛擬空間,否則確認是否正確執行了上面的命令。
伴隨著這個錯誤的出現,系統還會有一些軟件崩潰的癥狀,例如瀏覽器打開的網頁全部崩潰。如果出現這種癥狀,你一定是忘記分配虛擬空間了。
安裝TensorFlow
對于普通的Ubuntu、Windows等系統,TensorFlow提供了簡單的pip方式,分為有GPU和無GPU版本,但是pip安裝方式存在一個問題,TensorFlow執行CPU計算的效率低,沒有優化,所以最好的安裝方式是重新編譯源碼。另外,TX2的CPU是ARM架構,混合NVIDIA自家的CPU,所以目前只能重新編譯、再安裝TensorFlow。安裝步驟直接按照TensorFlow on NVIDIA Jetson TX2 Development Kit即可。
如果你參考了How to install TensorFlow on the NVIDIA Jetson TX2?”中修改TF源碼關于NUMA的部分。可能在你修改的時候,你會發現有所不同,文件tensorflow/stream_executor/cuda/cuda_gpu_executor.cc
中的TryToReadNumaNode()
函數源碼中已經添加了對aarch64
架構的識別和處理,
static int TryToReadNumaNode(const string &pci_bus_id, int device_ordinal){
#ifdef __aarch64__
LOG(INFO) << "ARM64 does not support NUMA - returning NUMA node zero";
return 0;
...
}
如果是這樣,就不必修改源碼。
否則,請閱讀下面內容,完成類似修改
由于TX2的ARM架構不支持NUMA,所以在build TensorFlow之前需要修改一下clone到本地的源碼,具體中添加如下兩行內容,避免后面使用TF的時候出現錯誤
LOG(INFO) << "ARM has no NUMA node, hardcoding to return zero";
return 0;
如圖: install TensorFlow v1.2.1 on TX2
To use mobilenet on TX2 for object detection task, I have to use a newer TensorFlow than version 1.0.1. TF 1.2.1 is good for me, while JetsonHacks does not give guide to install TF 1.2.1 or some other versions but 1.0.1. After searching the Internet and read many talks on nvidia jetson forum, I get TF 1.2.1 working on TX2. Here is the steps:
- install Bazel 0.5.2 from official website
nvidia@tegra-ubuntu:~$ bazel version
Build label: 0.5.2- (@non-git)
Build target: bazel-out/local- opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Aug 4 08:22:07 2017 (1501834927)
Build timestamp: 1501834927
Build timestamp as int: 1501834927
- clone and checkout v1.2.1 for tensorflow
# from $HOME/
git clone https://github.com/tensorflow/tensorflow
cd ./tensorflow
git checkout v1.2.1
- ./configure
./configure
All setting is default (just type ENTER) except for CUDA set to 'y'
- fix
workspace.bzl
to get the right Eigen version for out ARMv8 on TX2
worksapce.bzl
is in./tensorflow/tensorflow/
, feel free to open it use some text editor or vim, find lines as follows:
native.new_http_archive(
name = "eigen_archive",
urls = [
# "http://mirror.bazel.build/bitbucket.org/eigen/eigen/get/f3a22f35b044.tar.gz",
# "https://bitbucket.org/eigen/eigen/get/f3a22f35b044.tar.gz",
"http://mirror.bazel.build/bitbucket.org/eigen/eigen/get/d781c1de9834.tar.gz",
"https://bitbucket.org/eigen/eigen/get/d781c1de9834.tar.gz",
],
# sha256 = "ca7beac153d4059c02c8fc59816c82d54ea47fe58365e8aded4082ded0b820c4",
# strip_prefix = "eigen-eigen-f3a22f35b044",
sha256 = "a34b208da6ec18fa8da963369e166e4a368612c14d956dd2f9d7072904675d9b",
strip_prefix = "eigen-eigen-d781c1de9834",
build_file = str(Label("http://third_party:eigen.BUILD")),
)
the lines above those starting with #
are the source text, and I just use #
to commet these lines and new urls, sha256 and strip_prefix are added.
- bazel build
If you do notswapon swapfile
, do it before build TF and thenbazel build
as following.
bazel build -c opt --local_resources 3072,4.0,1.0 --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --verbose_failures --config=cuda //tensorflow/tools/pip_package:build_pip_package
then
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
now you get tensorflow 1.2.1 on /tem/tensorflow_pkg/
, use
sudo pip install tensorflow-1.2.1-cp27-cp27mu-linux_aarch64.whl