前言
上回我们安装了OpenCV 4.4,相信对源码编译库文件有了一定的了解,这篇我们进一步在树莓派上编译并安装 Pytorch 的最新版本。
文章目录

PyTorch 1.6 的新特性
PyTorch 1.6 版本增加了许多新的 API、用于性能改进和性能分析的工具、以及对基于分布式数据并行(Distributed Data Parallel, DDP)和基于远程过程调用(Remote Procedure Call, RPC)的分布式训练的重大更新。部分更新亮点包括:
- 原生支持自动混合精度训练(AMP, automatic mixed-precision training),只需增加几行新代码就可以提高大型模型训练50-60% 的速度。
- 为 tensor-aware 增加对 TensorPipe 的原生支持
- 在前端 API 增加了对 complex tensor 的支持
- 新的分析工具提供了张量级的内存消耗信息
- 针对分布式数据并行训练和远程过程调用的多项改进和新功能
增加交换内存(可选)
编译 torch 需要花费大量的内存,在低于 2g 或以下内存的树莓派上,可以通过增加虚拟内存来防止OOM,4g 或 8g 的版本的树莓派可跳过这步。
1. 修改配置文件
sudo nano /etc/dphys-swapfil
设置 4g 的交换内存,文件内容如下:
# /etc/dphys-swapfile - user settings for dphys-swapfile package
# author Neil Franklin, last modification 2010.05.05
# copyright ETH Zuerich Physics Departement
# use under either modified/non-advertising BSD or GPL license
# this file is sourced with . so full normal sh syntax applies
# the default settings are added as commented out CONF_*=* lines
# where we want the swapfile to be, this is the default
#CONF_SWAPFILE=/var/swap
# set size to absolute value, leaving empty (default) then uses computed value
# you most likely don't want this, unless you have an special disk situation
CONF_SWAPSIZE=4096
保存退出,重启服务生效。
sudo service dphys-swapfile restart
查看一下 swap 是否已调整。
swapon -s
PyTorch 安装环境依赖
1. 安装依赖
首先安装一些编译需要的依赖库ÿ