admin管理员组

文章数量:1575966

文章目录

  • 前言
  • 安装torch和torchvision
  • 安装cudatoolkit

前言

安装Pytorch,首先需要安装的是torch,做CV的常用的还有TorchVision,还有必不可少的cudatoolkit。

它们之间的版本有着严格的对应关系。

而官网提供的命令没有涵盖我们所需要的一些版本的对应(如下图所示),所以我们只能模仿官网的命令来下载。

我现在使用的是CUDA11.2,那么我要么使用cudatoolkit11.1和cudatoolkit11.2,而不能使用cudatoolkit11.3,因为不能向上兼容,只能向下兼容,升级CUDA很麻烦,我不想这么麻烦。

安装torch和torchvision

torch和torchvision对应关系

pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 -f https://download.pytorch/whl/torch_stable.html

注:conda install 可能找不到源包,那就在虚拟环境中用 pip install.

安装cudatoolkit

配置清华镜像:

conda config --add channels https://mirrors.tuna.tsinghua.edu/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu/anaconda/pkgs/main/
anaconda show Zimmf/cudatoolkit

查找cudatoolkit:

anaconda search -t conda cudatoolkit


找到我需要的11.1版本的那一行:

anaconda show Zimmf/cudatoolkit

发现它里面有10.2和11.1的版本,选择我需要的11.1,安装:

conda install --channel https://conda.anaconda/Zimmf cudatoolkit=11.1

本文标签: 版本历史PytorchtorchTorchVision