1.安装pytorch
- 对于安装pytorch你要结合你的cuda的版本,以及你的python版本,由于我是jetson nano的平台,所以安装的时候要注意有aarch64的后缀,pytorch就是蛮难下下来的,需要你翻墙才能下载,下面我会给出相应的pytorch的腾讯微云分享版本
这是全部的下载链接,直接找对应下载:
https://elinux.org/Jetson_Zoo#PyTorch_.28Caffe2.29
首先给出下载pytorch的代码,如果运行不起就直接https://nvidia.box.com/shared/static/j2dn48btaxosqp0zremqqm8pjelriyvs.whl
wget https://nvidia.box.com/shared/static/j2dn48btaxosqp0zremqqm8pjelriyvs.whl -O torch-1.6.0-cp36-cp36m-linux_aarch64.whl
sudo pip3 install torch-1.6.0-cp36-cp36m-linux_aarch64.whl
- ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory
- solve: sudo apt-get install libopenblas-dev
- OSError: libmpi_cxx.so.20: cannot open shared object file: No such file or directory
- solve:
安装完了之后就可以通过下面的这个验证
import torch
print(torch.__version__)
print('CUDA available: ' + str(torch.cuda.is_available()))
a = torch.cuda.FloatTensor(2).zero_()
print('Tensor a = ' + str(a))
b = torch.randn(2).cuda()
print('Tensor b = ' + str(b))
c = a + b
print('Tensor c = ' + str(c))
2.安装torchvision
# 安装一些必要的依赖包
sudo apt-get install libjpeg-dev zlib1g-dev
# 下载torchvision
git clone --branch v0.7.0 https://gitee.com/zero-one-game/vision torchvision
# 安装torchvision
cd torchvision
sudo python3 setup.py install
# OSError: libmpi_cxx.so.20: cannot open shared object file: No such file or directory ->>>>sudo apt-get install libopenmpi2
cd ../
pip3 install 'pillow<7'
- error: command ‘aarch64-linux-gnu-gcc‘ failed with exit status 1
- way1: sudo apt-get install python3-dev python3-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
- way2: if has ffmpeg 改为if False即可
用以下代码测试是否成功
import torchvision
print(torchvision.__version__)
在Jetson Xavier NX上安装torchvision编译报错:fatal error: libavcodec/avcodec.h: No such file or directory
look at the authou csdn
3.安装opencv-python(自带有)
一条命令直接搞定
sudo apt-get install python3-opencv
通过终端验证直接通过
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
若要删除用sudo apt-get remove python3-opencv
4.安装onnx/onnxruntime
- 先安装onnx的环境依赖
sudo apt-get install protobuf-compiler libprotoc-dev - 再安装onnx为1.9.0的版本
pip install onnx1.9.0
pip3 install onnxruntime1.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
Created wheel for onnx: filename=onnx-1.4.1-cp36-cp36m-linux_aarch64.whl size=3646291 sha256=3632a794d71e5c744920b2abf7626a4fd3ca39b7ea47a85e7cb9f3a7c325dbf7
Stored in directory: /home/lqs/.cache/pip/wheels/45/d1/9f/9508c4176d79c0373629eff6cf2645e2dcbfb291bbe9dc2f8a
Successfully built onnx
Installing collected packages: onnx
Successfully installed onnx-1.4.1
5.安装tensorflow-gpu
if your platform is jetson xavier nx,I think you should see the offcial word,the website is :https://forums.developer.nvidia.com/t/official-tensorflow-for-jetson-agx-xavier/65523
jetson nano look at here
- 我这里安装的是tensorflow-gpu1.15版本的,下面是下载的地址
https://developer.download.nvidia.com/compute/redist/jp/v42
下好了之后在终端输入
先安装依赖再安装tensorflow:
1.sudo apt install python3-pip python3-dev
2.python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
#使用下述指令可以更改python镜像源为清华pypi镜像源
3.pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
4.#安装机器学习常用包
sudo apt install python3-scipy -y
sudo apt install python3-pandas -y
sudo apt install python3-sklearn -y
sudo apt install python3-seaborn -y
sudo pip install cython
上述指令会自动安装numpy和matplotlib等依赖包
5.
sudo apt-get update
sudo apt install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran
6.#安装Python依赖包
sudo pip3 install -U numpy==1.16.1 future==0.18.2 mock==3.0.5 h5py==2.10.0 keras_preprocessing==1.1.1 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11 astor
7.#download tensorflow https://developer.download.nvidia.com/compute/redist/jp/v45
pip3 install tensorflow-1.15.5+nv21.4-cp36-cp36m-linux_aarch64.whl --user
8.test
import tensorflow as tf
# 输出提示:
# 2020-10-11 15:25:36.253267: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.2
a = tf.constant(1.)
b = tf.constant(2.)
print(a+b)
# 输出结果:
# tf.Tensor(3.0, shape=(), dtype=float32)
print('GPU:', tf.test.is_gpu_available())
# 输出最后一句为:
# GPU: True
#this is NV
pip3 install tensorflow-1.15.5+nv21.3-cp36-cp36m-linux_aarch64.whl
# jetson xavier nx jetpack 4.5.2 cuda 10.2
- 验证
6.安装setuptools
pip install --no-cache-dir setuptools==20.7.0 -i https://pypi.doubanio.com/simple/
#下面是升级
pip install --ignore-installed setuptools
7.安装Pycuda
tar zxvf pycuda-2019.1.2.tar.gz
cd pycuda-2019.1.2/
python3 configure.py --cuda-root=/usr/local/cuda-10.2
sudo python3 setup.py install
- 若报错FileNotFoundError: [Errno 2] No such file or directory: ‘nvcc’
- 打开Pycuda的compiler.py文件中的compile_plain()
中,大约在第 73 行的位置中加入下面段代码!
8. 安装Cmake
wget http://www.cmake.org/files/v3.13/cmake-3.13.0.tar.gz
tar xpvf cmake-3.13.0.tar.gz cmake-3.13.0/
cd cmake-3.13.0/
./bootstrap --system-curl
make -j4
echo 'export PATH=/home/z/Downloads/cmake-3.13.0/bin/:$PATH' >> ~/.bashrc
source ~/.bashrc
9. 安装matplotlib
sudo apt-get install python3-matplotlib
10. 安装pyqt5
sudo apt install pyqt5*
sudo apt-get install python3-pyqt5