在本文之前,先推荐一个大佬的博客,https://blog.csdn.net/huiyuanliyan/article/details/87874024
他有着一系列的Xavier的文章
友情提示,Xavier自带的30G内存不够用,最好加入sd卡或者硬盘
什么是Nvidia Jetson Xavier
Nvidia Jetson Xavier是一个功能强大的嵌入式的AI计算平台,有着高性能、低功耗的优点,在自动驾驶领域有着很大的潜力。
具体的参数我就不介绍了,官网上有详细的介绍。
给Xavier刷JetPack4.2
JetPack是Nvidia官方的一个工具包,包含了一系列的Xavier所需要的软件。首先需要一个linux系统的电脑,在电脑上安装JetPack4.2 SDK Manager,从下面链接下载软件
https://developer.nvidia.com/embedded/jetpack
然后双击软件包安装就行。
安装完成之后,打开软件,然后不断点击下一步,中间有一步要下载一堆软件,会耗费很长时间,然后是这个界面
我在这里选择自动安装并没有成功,所以就选择了手动安装,在安装之前,要将Xavier通过线连接到电脑上,然后按住中间按钮,不松手的同时按住左边按钮,然后同时松开两个按钮,然后在电脑上点击Flash,就可以进行刷机了。刷机首先是给Xavier安装一个Ubuntu18.04,然后在系统完成之后,需要给Xavier安装一个键盘鼠标,按照装linux 的步骤完成linux的安装。然后将账户密码输入到电脑中,完成Cuda、opencv等软件的安装,这样就完成刷机过程。
配置清华源
在Xavier中更换源,需要对源稍作修改,在更换软件源的时候,需要注意,清华源的格式为
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
应该将其改成
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
加一个-ports,这是因为xavier中自带的源的格式就是这样的
安装tensorflow1.13
首先安装jdk1.8
sudo apt-get install openjdk-8-jdk
然后下载bazel0.19.2,从https://github.com/bazelbuild/bazel/releases/tag/0.19.2
网站下载bazel-0.19.2-dist.zip,这是bazel的源码,然后我们需要编译它。
编译的时候需要注意,先新建一个bazel的文件夹,然后将压缩包移动进去,在文件夹内解压
unzip bazel-0.19.2-dist.zip
然后编译源码
bash ./compile.sh.
编译会持续很久的时间,当然这个时间和后面tensorflow的编译时间相比就差远了= =
编译产生的文件放在./output里面,然后执行下面的代码将这个路径添加到环境变量中
vim ~/.bashrc
export PATH=/pathToYourBazelDirectory/output${PATH:+:${PATH}}
安装tensorflow1.13
首先是安装依赖,不然的话会报错误
sudo apt-get install autoconf automake libtool curl make # Protobuf Dependencies
下载源码
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout r1.13
然后需要修改部分代码,这部分中-代表删除,+代表添加
首先是./tensorflow/lite/kernels/internal/BUILD
diff --git a/tensorflow/lite/kernels/internal/BUILD b/tensorflow/lite/kernels/internal/BUILD
index 4be3226938..7226f96fdf 100644
--- a/tensorflow/lite/kernels/internal/BUILD
+++ b/tensorflow/lite/kernels/internal/BUILD
@@ -22,15 +22,12 @@ HARD_FP_FLAGS_IF_APPLICABLE = select({
NEON_FLAGS_IF_APPLICABLE = select({
":arm": [
"-O3",
- "-mfpu=neon",
],
":armeabi-v7a": [
"-O3",
- "-mfpu=neon",
],
":armv7a": [
"-O3",
- "-mfpu=neon",
],
"//conditions:default": [
"-O3",
然后是./third_party/aws/BUILD.bazel b/third_party/aws/BUILD.bazel
diff --git a/third_party/aws/BUILD.bazel b/third_party/aws/BUILD.bazel
index 5426f79e46..e08f8fc108 100644
--- a/third_party/aws/BUILD.bazel
+++ b/third_party/aws/BUILD.bazel
@@ -24,7 +24,7 @@ cc_library(
"@org_tensorflow//tensorflow:raspberry_pi_armeabi": glob([
"aws-cpp-sdk-core/source/platform/linux-shared/*.cpp",
]),
- "//conditions:default": [],
+ "//conditions:default": glob(["aws-cpp-sdk-core/source/platform/linux-shared/*.cpp",]),
}) + glob([
"aws-cpp-sdk-core/include/**/*.h",
"aws-cpp-sdk-core/source/*.cpp",
最后是./third_party/gpus/crosstool/BUILD.tpl b/third_party/gpus/crosstool/BUILD.tpl
diff --git a/third_party/gpus/crosstool/BUILD.tpl b/third_party/gpus/crosstool/BUILD.tpl
index db76306ffb..184cd35b87 100644
--- a/third_party/gpus/crosstool/BUILD.tpl
+++ b/third_party/gpus/crosstool/BUILD.tpl
@@ -24,6 +24,7 @@ cc_toolchain_suite(
"x64_windows|msvc-cl": ":cc-compiler-windows",
"x64_windows": ":cc-compiler-windows",
"arm": ":cc-compiler-local",
+ "aarch64": ":cc-compiler-local",
"k8": ":cc-compiler-local",
"piii": ":cc-compiler-local",
"ppc": ":cc-compiler-local",
然后安装gcc-5,这个据说是因为自带的gcc7.4版本太高,我没有去对比测试,反正这样是可以成功的。
sudo apt-get install gcc-5
接下来是创建交换分区,这个是因为Xavier自带的内存不够用,必须使用交换分区才行,我当初没有创建,编译了五个小时之后报错。。。
$ fallocate -l 8G swapfile
$ ls -lh swapfile
$ sudo chmod 600 swapfile
$ ls -lh swapfile
$ sudo mkswap swapfile
$ sudo swapon swapfile
$ swapon -s
然后就是配置configure文件
1. $./configure
2. Please specify the location of python. [Default is /usr/bin/python]:/usr/bin/python3
5. Found possible Python library paths:
6. /usr/local/lib/python3.6/dist-packages
7. /usr/lib/python3.6/dist-packages
8. Please input the desired Python library path to use. Default is [/usr/local/lib/python3.6/dist-packages]
10. Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
11. No XLA JIT support will be enabled for TensorFlow.
13. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
14. No OpenCL SYCL support will be enabled for TensorFlow.
16. Do you wish to build TensorFlow with ROCm support? [y/N]: n
17. No ROCm support will be enabled for TensorFlow.
19. Do you wish to build TensorFlow with CUDA support? [y/N]: y
20. CUDA support will be enabled for TensorFlow.
22. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]:
25. Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:/usr/local/cuda-10.0
28. Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]:
31. Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:/usr/lib/aarch64-linux-gnu
34. Do you wish to build TensorFlow with TensorRT support? [y/N]: y
35. TensorRT support will be enabled for TensorFlow.
37. Please specify the location where TensorRT is installed. [Default is /usr/lib/aarch64-linux-gnu]:
40. Please specify the locally installed NCCL version you want to use. [Default is to use [https://github.com/nvidia/nccl]:](https://github.com/nvidia/nccl]:)
43. Please specify a list of comma-separated Cuda compute capabilities you want to build with.
44. You can find the compute capability of your device at: [https://developer.nvidia.com/cuda-gpus.](https://developer.nvidia.com/cuda-gpus.)
45. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 3.5,7.0]: 7.2
48. Do you want to use clang as CUDA compiler? [y/N]: n
49. nvcc will be used as CUDA compiler.
51. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:/usr/bin/gcc-5
54. Do you wish to build TensorFlow with MPI support? [y/N]: n
55. No MPI support will be enabled for TensorFlow.
57. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]:
60. Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
61. Not configuring the WORKSPACE for Android builds.
然后编译tensorflow
bazel build --config=opt --config=nonccl //tensorflow:libtensorflow_cc.so --incompatible_remove_native_http_archive=false --verbose_failures --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
这个编译大概持续十几个小时,编译完成之后,使用官网给的测试代码进行测试
https://www.tensorflow.org/guide/extend/cc
按照官网的教程一步步来就行,在这里的时候,可能是我的依赖没有安装完全,第一次编译又耗费了十个小时左右,编译了一堆文件。后面再编译就不需要那么久了。
这是使用bazel进行c++代码的编译,我常用的编译方式是cmake编译,下面是我用的CMakeLists.txt文件
cmake_minimum_required(VERSION 2.8)
#SET(CMAKE_CXX_COMPILER "/usr/bin/g++-5")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0")
project(tf_project)
set(SOURCE_FILES test.cpp)
set(EXECUTE_FILE tf_test)
find_package(OpenCV REQUIRED )
set(TENSORFLOW_DIR /mnt/sd/tensorflow/)
include_directories(${TENSORFLOW_DIR})
include_directories(${TENSORFLOW_DIR}/tensorflow)
include_directories(${TENSORFLOW_DIR}/bazel-tensorflow/external/eigen_archive)
include_directories(${TENSORFLOW_DIR}/bazel-tensorflow/external/protobuf_archive/src)
include_directories(${TENSORFLOW_DIR}/bazel-tensorflow/external/com_google_absl)
include_directories(${TENSORFLOW_DIR}/bazel-genfiles)
include_directories(${TENSORFLOW_DIR}/tensorflow/cc)
include_directories(${TENSORFLOW_DIR}/tensorflow/core)
link_directories(${TENSORFLOW_DIR}/bazel-bin/tensorflow)
add_executable(${EXECUTE_FILE} ${SOURCE_FILES})
target_link_libraries(${EXECUTE_FILE} ${TENSORFLOW_DIR}/bazel-bin/tensorflow/libtensorflow_cc.so)
target_link_libraries(${EXECUTE_FILE} ${TENSORFLOW_DIR}/bazel-bin/tensorflow/libtensorflow_framework.so)
target_link_libraries(${EXECUTE_FILE} ${OpenCV_LIBS})
不知道为啥,这里我使用默认的gcc7.4完全没有问题,感觉很玄学,而且最玄学的一点是这个cmake方式跑不通官方给的测试代码,但是能跑通我的代码。。。希望有大神能帮我解惑
到这里为止就完成了tensorflow1.13的安装