Jetson Nano witth Jetpack4.6 Install Torch, Torch Vision and ROS

Jetson Nano witth Jetpack4.6 Install Torch, Torch Vision and ROS

  • 0 镜像文件写入microSD卡
    • 0.1 先给microSD卡格式化
    • 0.2 使用软件将镜像文件写入microSD卡
  • 1 ubuntu流程(略)
  • 2 开机后环境配置
    • 2.1 配置CUDA
    • 2.2 update system and install depends
    • 2.3 Jestin nano 刷机后环境初始化
  • 3 Tensorflow and pytorch安装
    • 3.1 tensorflow 安装链接
    • 3.2 安装torch
    • 3.3 安装torchvision
  • 4 archiconda3
  • 5 Install the ROS System
  • 6 安装opencv (jetpack>=4.5 don't need it)
  • 7 Jetson Nano 更换镜像源
  • 8 Jetson Nano 版本对应
    • 8.1 JetPack与Pytorch版本
    • 8.2 PyTorch与TorchVision版本

JetPack4.5下载链接

0 镜像文件写入microSD卡

0.1 先给microSD卡格式化

格式化文件:
SD Card Formatter:SD Card Formatter下载传送点

0.2 使用软件将镜像文件写入microSD卡

任选其一:
(1)balena:https://www.balena.io/etcher/
(2)win32diskimager:https://sourceforge.net/projects/win32diskimager/

1 ubuntu流程(略)

2 开机后环境配置

2.1 配置CUDA

# open环境变量:
vim ~/.bashrc   #或者采用 source gedit ~/.bashrc
 
#在最后写入并保存:
export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
 
#使其生效:
source ~/.bashrc
 
#查看是否生效:
cat /proc/driver/nvidia/version
nvcc -V

2.2 update system and install depends

sudo apt-get update
sudo apt-get install libhdf5-serial-dev hdf5-tools zlib1g-dev zip libjpeg8-dev libhdf5-dev  python3-pip python-h5py

2.3 Jestin nano 刷机后环境初始化

分别执行以下命令,即可查看自己的jetson nano 预搭载的CUDA版本
sudo pip3 install jetson-stats
sudo jtop

3 Tensorflow and pytorch安装

3.1 tensorflow 安装链接

快速安装链接:https://developer.download.nvidia.com/compute/redist/jp/v42/tensorflow-gpu/
Tensorflow for Jetson Nano

#install tensorflow
sudo pip install --ignore-installed --upgrade tensorflow_gpu-1.3.0-cp36-cp36m-linux_x86_64.whl

3.2 安装torch

pytorch快速安装链接:官网whl链接

wget https://nvidia.box.com/shared/static/p57jwntv436lfrd78inwl7iml6p13fzh.whl -O torch-1.7.0-cp36-cp36m-linux_aarch64.whl
sudo apt-get install python3-pip libopenblas-base libopenmpi-dev 
pip3 install Cython
pip3 install numpy torch-1.7.0-cp36-cp36m-linux_aarch64.whl

3.3 安装torchvision

(官网github源码下载)

$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
$ git clone --branch v0.8.1 https://ghproxy.com/https://github.com/pytorch/vision torchvision   # see below for version of torchvision to download
$ cd torchvision
$ export BUILD_VERSION=0.8.1  # where 0.x.0 is the torchvision version  
$ python3 setup.py install --user    #long time for it 
$ cd ../  # attempting to load torchvision from build dir will result in import error
$ pip install 'pillow<7' # always needed for Python 2.7, not needed torchvision v0.5.0+ with Python 3.6
#换成码云下载torchvision
$ git clone --branch v0.8.1 https://gitee.com/zero-one-game/vision 

指定镜像安装pillow

sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
python3 -m pip install -i https://mirrors.aliyun.com/pypi/simple pillow

4 archiconda3

https://github.com/yqlbu/archiconda3

#open the file
vim ~/.bashrc
#archiconda3
export PATH="/home/klx/archiconda3/bin:$PATH"
#update the file
source ~/.bashrc

5 Install the ROS System

#enable all Ubuntu packages:
$ sudo apt-add-repository universe
$ sudo apt-add-repository multiverse
$ sudo apt-add-repository restricted


#add ROS repository to apt sources
$ sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654


#install ROS Base
$ sudo apt-get update
$ sudo apt-get install ros-melodic-ros-base


#add ROS paths to environment
sudo sh -c 'echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc'

6 安装opencv (jetpack>=4.5 don’t need it)

安装opencv依赖项,用aptitude来进行操作:
# Update
sudo apt-get update
sudo apt-get upgrade
# Pre-requisites
sudo aptitude install build-essential cmake unzip pkg-config
sudo aptitude  install libjpeg-dev libpng-dev libtiff-dev
sudo aptitude  install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo aptitude  install libxvidcore-dev libx264-dev
 
#下面这个会告诉你有冲突项,你第一次选择n,第二次之后选择y即可
sudo aptitude  install libgtk-3-dev
sudo aptitude  install libatlas-base-dev gfortran
sudo aptitude  install python3-dev

1.首先扩大jetson nano的内存,因为要下载opencv的源码并编译,之后还要安装tensorflow,所以可能内存不够大,要增加内存。可以进入github:https://github.com/JetsonHacksNano查看并下载
或者直接在命令行操作

git clone https://github.com/JetsonHacksNano/installSwapfile
./installSwapfile.sh #编译文件,默认扩大6G内存

2.下载编译opencv

git clone https://github.com/JetsonHacksNano/buildOpenCV
./buildOpenCV.sh #编译opencv

或者 pip3 install opencv-python
3.测试

python3
import cv2
cv2.__version__
  1. The second method: sudo apt-get install python3-opencv
  2. The third method:https://www.jianshu.com/p/99bdc2472423

Jetson Nano使用教程:
(1)http://www.yoyojacky.com/?p=513

7 Jetson Nano 更换镜像源

orign镜像源

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic universe
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security universe
deb http://ports.ubuntu.com/ubuntu-ports/ bionic-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ bionic-security multiverse
1、更换
NVIDIA官方提供的Linux镜像版本为Ubuntu 18.04 LTS,镜像默认的是Ubuntu官方源,在国内使用该源下载程序速度较慢,所以需要更换。

打开/etc/apt/sources.list文件,注释原内容,在末尾添加下述内容(以清华大学镜像源为例,注意镜像源需要支持arm64架构):

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse

2、其他镜像源
下面提供了国内几个支持arm64架构的Ubuntu镜像源:

清华大学镜像源:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse


中国科学技术大学镜像源:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic main restricted universe multiverse
# deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates main restricted universe multiverse
# deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports main restricted universe multiverse
# deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security main restricted universe multiverse
# deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb http://mirrors.ustc.edu.cn/ubuntu-ports bionic-proposed main restricted universe multiverse
# deb-src http://mirrors.ustc.edu.cn/ubuntu-ports bionic-proposed main restricted universe multiverse


阿里巴巴镜像站:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/s bionic-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.aliyun.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse

3、系统更新
系统源和软件源配置完成以后,使用下述两条命令更新:

sudo apt update
sudo apt upgrade -y

8 Jetson Nano 版本对应

8.1 JetPack与Pytorch版本

Jetson Nano witth Jetpack4.6 Install Torch, Torch Vision and ROS_第1张图片

8.2 PyTorch与TorchVision版本

Jetson Nano witth Jetpack4.6 Install Torch, Torch Vision and ROS_第2张图片

你可能感兴趣的:(ROS,ubuntu,linux,运维)