NVIDIA JETSON XAVIER NX (三)配置环境

文章目录

    • (1) jetson apt 换源
    • (2) pip 安装换源
    • (3) 安装相关 py 库
    • (4) TensorRT 配置

(1) jetson apt 换源

首先需要搞清楚的是:

1. Jetson Xavier NX 默认系统是 Ubuntu18.04LTS,对应源关键字:“bionic”
2. Jetson Xavier NX CPU是arm64的架构,镜像路径:xxx/ubuntu-ports/

之后就可以修改源文件了:

sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak # 将原镜像源文件做一个备份
sudo gedit /etc/apt/sources.list # 用文本编辑器打开源文件进行编辑,将下面的apt源内容写入这个文件中(华为、清华都可以,貌似华为对于pycuda的下载友好点)。

# huawei
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse

deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse

deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse

deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse

# qinghua
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main universe restricted
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main universe restricted

换源结束后别忘了更新下apt哦!

# updating
sudo apt-get update
sudo apt-get upgrade

(2) pip 安装换源

pip也是一种高级的包管理工具,一般python环境都使用pip进行搭建,所以我们安装pip并进行换源。

# 安装(因为有很多依赖包,所以提前都安装下)
sudo apt-get install libhdf5-serial-dev hdf5-tools zlib1g-dev zip libjpeg8-dev libhdf5-dev  python3-pip
# 换源(win下也是在用户文件中创建.pip文件夹,建立pip源配置文件)
mkdir ~/.pip
vim ~/.pip/pip.conf
# USTC
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple
[install]
trusted-host = https://pypi.mirrors.ustc.edu.cn
# qinghua
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

# (esc按住 -> : -> wq! -> enter)强制读写

最后更新下pip就行了

# updating
python3 -m pip install --upgrade pip
# 查看pip版本
pip3 -V

(3) 安装相关 py 库

python相关的工具库

# apt installing
sudo apt-get install python3-numpy
sudo apt-get install python3-matplotlib
sudo apt-get install python3-scipy

# pip installing (when failed to build some-package)
sudo pip3 install Pillow
sudo pip3 install numpy	# 需要编译安装,用时很长,可单独安装(-U: updating)
sudo pip3 install h5py	# 需要编译安装,用时非常长,nx装这个20多分钟才装完(numpy==1.19.0 搭配 h5py==2.10.0)
sudo pip3 install -U grpcio absl-py py-cpuinfo psutil portpicker six mock requests gast astor termcolor

常见的安装问题:

  1. python3-dev安装不了可能是换源的时候update因网络问题导致update失败,之后找不到python3-dev文件 。
  2. h5py安装编译不成功可能除了numpy版本过高还有可能是没安装cython
  3. 中文输入法安装:
    sudo apt-get install ibus-pinyin
    
    然后打开系统设置选择language support,添加语言中文(简体),应用后等待安装后,点击应用到整个系统,重启系统后,输入ibus-setup,输入法界面点击添加汉语,intelligent Pinyin,完成后输入ibus restart 。
  4. 将cuda环境写入环境变量:
    sudo vim ~/.bashrc
    # i -> end of text to edit
    ###
    export PATH=/usr/local/cuda/bin:$PATH
    export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
    export CUDA_ROOT=/usr/local/cuda
    ###
    # Esc+: -> wq! -> enter
    source ~/.bashrc
    nvcc -V
    

安装Tensorflow:(推荐使用whl离线安装,这样出错的概率较小)

# 依赖环境安装
sudo apt-get install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
# 本地whl安装(进入whl目录下终端)
pip3 install (name.whl)

(4) TensorRT 配置

目前更新了Jetpack4.5,基本的 cuda、cuDNN 以及 tensorRT 都包含在内,主要配置 DarkNet 中的 YOLO 转 TRT 的环境。

实现思路:
yolo模型(.weights + .cfg) → onnx文件(.onnx) → tensorRT模型(.trt)

安装ONNX:

# 依赖项
sudo apt-get install protobuf-compiler libprotoc-dev 
pip install onnx==1.4.1

安装PYCUDA

# 修改环境变量地址,或者直接vim打开.bashnrc,底部添加
export PATH=/usr/local/cuda/bin:\${PATH}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:\${LD_LIBRARY_PATH}

sudo pip3 install pycuda

References:
① tensorRT环境搭建
② tensorRT推理优化
③ tensorRT基本流程

你可能感兴趣的:(NVIDIA,JETSON,XAVIER,NX,ubuntu,pip,深度学习)