被JHU Data Science課虐的頭昏腦漲,決定換換腦子,回頭玩Jetson Nano,再向前推進一步。核心思路是,在Nano板子上配置好python,Anaconda和PyTorch環境。
如無特別指明,以下命令都是在ssh登錄到jetson nano後遠程執行。
用zsh替代默認的bash,並安裝oh-my-zsh$ apt install curl$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"python$ sudo apt install python3-pip python3-dev libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev$ pip3 -V pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)首先將pip版本從9.0.1升級到最新的20.2.2,升級之後可以更換為清華源,提高訪問速度 https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
$ python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple $ pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple2. Anaconda
Anaconda安裝比較簡單,不贅述了。以下簡要記述安裝過程。
需要注意的是,Jetson Nano的CPU是aarch64架構,對應地,Anaconda有針對aarch64架構的發行版,叫做Archiconda,這是github上的Archiconda主頁,網址在https://github.com/Archiconda/build-tools,感興趣的不妨上去看看。
下載$ mkdir ~/Soft$ cd ~/Soft$ wget https://github.com/Archiconda/build-tools/releases/download/0.2.3/Archiconda3-0.2.3-Linux-aarch64.sh$ chmod +x ./Archiconda3-0.2.3-Linux-aarch64.sh$ sh ./Archiconda3-0.2.3-Linux-aarch64.sh安裝
$ sudo ./Archiconda3-0.2.3-Linux-aarch64.sh改成清華源,提高訪問速度
$ touch ~/.condarc$ vim ~/.condarc填入如下內容(來自https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/)
channels: - defaultsshow_channel_urls: truechannel_alias: https:default_channels: - https: - https: - https: - https: - https:custom_channels: conda-forge: https: msys2: https: bioconda: https: menpo: https: pytorch: https: simpleitk: https:清除索引緩存,確保清華源生效
然後就是建立一個名為work的虛擬環境,可以在裡面隨意折騰了
$ conda update -n base conda $ conda create -n work python=3.6 $ conda activate work3. PyTorch & torchvisionJetson Nano在官方image中已經預集成了GPU驅動,不需要額外下載nvidia-driver-430等PCIe驅動,可見https://forums.developer.nvidia.com/t/nvidia-driver-not-included-in-the-image-for-jetson-nano/76795
NVIDIA官方提供了Jetson Nano的PyTorch 1.6.0和torchvision的下載,照著操作就行了,見https://forums.developer.nvidia.com/t/pytorch-for-jetson-nano-version-1-6-0-now-available/72048。注意:JetPack 4.4 (L4T R32.4.3)只支持PyTorch 1.6.0 or newer (due to updates in cuDNN).
首先是pytorch
$ cd ~/Soft$ wget https://nvidia.box.com/shared/static/9eptse6jyly1ggt9axbja2yrmj6pbarc.whl -O torch-1.6.0-cp36-cp36m-linux_aarch64.whl$ sudo apt-get install python3-pip libopenblas-base libopenmpi-dev$ conda install Cython$ conda install numpy$ pip3 install ./torch-1.6.0-cp36-cp36m-linux_aarch64.whl然後是torchvision。注意:與PyTorch 1.6.0對應的torchvision版本是0.8.0
$ sudo apt install libjpeg-dev zlib1g-dev$ git clone --branch 0.8.0 https://github.com/pytorch/vision torchvision$ cd torchvision$ export BUILD_VERSION=0.8.0 $ sudo python3 setup.py install測試一下吧
$ python3.6Python 3.6.9 (default, Jul 17 2020, 12:50:27)[GCC 8.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import torch>>> print(torch.__version__)1.6.0>>> print('CUDA available: ' + str(torch.cuda.is_available()))CUDA available: True>>> print('cuDNN version: ' + str(torch.backends.cudnn.version()))cuDNN version: 8000>>> a = torch.cuda.FloatTensor(2).zero_()>>> print('Tensor a = ' + str(a))Tensor a = tensor([0., 0.], device='cuda:0')>>> b = torch.randn(2).cuda()>>> print('Tensor b = ' + str(b))Tensor b = tensor([-1.3437, 0.1451], device='cuda:0')>>> c = a + b>>> print('Tensor c = ' + str(c))Tensor c = tensor([-1.3437, 0.1451], device='cuda:0')$ python3.6>>> import torchvision>>> print(torchvision.__version__)0.8.0a0+5f616a24. Next Steps組裝jetbot小車的硬體
配置,讓nano能夠指揮jetbot小車動起來