Pytorch是著名的人工智能框架,在部署人工智能项目的时候,就需要在嵌入式开发板上安装pytorch,下面就详解介绍关于安装pytorch的步骤
1.更换apt源
首先检查apt源是否已经是国内镜像源
输入:
sudo apt-get update
如果不是国内镜像的话
依次输入一下命令
cd /etc/apt
cp /etc/apt/sources.list /etc/apt/sources.list.bak
gedit sources.list
打开之后把里面的内容替换为;
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
再次输入
sudo apt-get update
查看是否换源成功
2.更换pip源
输入:
pip3 install --upgrade pip
检查是否换源
如果没有依次输入以下命令
mkdir ~/.pip
gedit ~/.pip/pip.conf
把一下内容粘贴进去:
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple
[install]
trusted-host = https://pypi.mirrors.ustc.edu.cn
既可以完成pip换源
3.开始安装pytorch
这里以torch-1.8.0和torchvison0.9.0为例
一定一定要把torch和torchvison版本对应起来
具体版本如何对应请查看
开始安装torch依赖
sudo apt-get install python3-pip libopenblas-base libopenmpi-dev libomp-dev
pip3 install Cython
安装pytorch
pip3 install numpy torch-1.8.0-cp36-cp36m-linux_aarch64.whl
安装完之后运行python3,输入
import torch
print(torch.__version__)
查看是否安装成功
安装torchvison
输入:
sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
cd torchvision
export BUILD_VERSION=0.9.0 #python3 setup.py install --user
cd ../
pip install 'pillow<7'
启动python3输入:
import torch
import torchvision
print(torch.__version__)
print(torchvision.__version__)
检查完全安装成功