ubuntu18安装pytorch1.3

环境:

ubuntu18

anaconda

创建一个新的环境

conda create -n env_name python=version

激活并进入环境中

conda activate env_name

pip更改清华源(https://mirrors.tuna.tsinghua.edu.cn/help/pypi/)

conda更换清华源,这个似乎更新的慢一些?(https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/)

conda list 看有没有cuda,cudnn,没有的话下面再装(conda install cudatoolkit conda install cudnn)最好自己指定下版本号 (发文时是10.1 和7.6)

安装pytorch

pip install torch torchvision

然后将pytorch 添加到jupyter notebook中(要在对应的环境下操作)

install ipykernel

python -m ipykernel install --user --name pytorch --display-name "Python (pytorch)"

查看列表jupyter kernelspec list

删除指定kernel:jupyter kernelspec remove icsharpkernel

某出品的教程

https://tangshusen.me/Dive-into-DL-PyTorch/#/

写个小程序测试一下

pytorch优化技巧

1.预处理时间长用Nvidia DALI:https://github.com/NVIDIA/DALI

原理:将原本cpu上的数据预处理步骤放到gpu上并行提速。

2.读取数据的io时间长用prefetch:https://pypi.org/project/prefetch_generator/

原理:在网络训练的同时从硬盘加载下一批数据。

3.训练时间长用apex:https://github.com/NVIDIA/apex

原理:fp16混合精度训练减少显存(增大batch size)