(conda + pip) Configure o ambiente de aprendizado profundo de cada versão do Pytorch

1. Introdução

  • Ao usar o Anaconda para configurar o ambiente de aprendizado profundo Pytorch, as instruções de instalação fornecidas pelo link do site oficial serão muito lentas e erros serão relatados com frequência. Para esse fim, a versão principal atual das instruções de configuração do ambiente de aprendizado profundo Pytorch é compilada. O seguinte as instruções são adequadas para sistemas operacionais Windows e são executadas no Prompt do Anaconda .
  • Além disso, às vezes, ao usar o conda para instalar, um erro será relatado. O artigo inclui instruções de instalação do pip. Como o método de instalação do pip fornecido no site oficial é um tanto hostil, algumas melhorias foram feitas no artigo. A maioria das instruções são eficazes em testes pessoais.

Insira a descrição da imagem aqui

2. Configure a fonte do espelho

Deixe-me avisar com antecedência : se um erro HTTP for relatado após configurar a fonte do espelho, você só precisará excluir os s em https://... no link da fonte.
Fonte Tsinghua

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --set show_channel_urls yes

Dayuan de Ciência e Tecnologia da China

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes

3. Versões correspondentes de pytorch, torchvision e python

O relacionamento correspondente entre pytorch, torchvision e python vem do github oficial do pytorch, link: https://github.com/pytorch/vision#installation

Insira a descrição da imagem aqui

4. Crie e entre no ambiente virtual

Crie um ambiente virtual, onde pt é o nome do ambiente virtual personalizado. Além disso, com base na experiência de armadilha, a versão python 3.6.5 pode se adaptar a mais versões do pytorch e alguns pacotes adicionais. Recomenda-se selecionar a versão 3.6.5 para a versão do interpretador python ao criar um ambiente.

conda create -n pt python=3.6.5

Em seguida, clique em y para concordar com a instalação e aguarde um pouco para entrar no ambiente virtual.

activate pt

5. Pytorch 0.4.1

# conda
conda install pytorch==0.4.1 torchvision==0.2.1 cuda90  # CUDA 9.0
conda install pytorch==0.4.1 torchvision==0.2.1 cuda92  # CUDA 9.2
conda install pytorch==0.4.1 torchvision==0.2.1 cuda80  # CUDA 8.0
conda install pytorch==0.4.1 torchvision==0.2.1 cuda75  # CUDA 7.5
conda install pytorch==0.4.1 torchvision==0.2.1 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 9.0
pip install https://download.pytorch.org/whl/cu92/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 9.2
pip install https://download.pytorch.org/whl/cu80/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 8.0
pip install https://download.pytorch.org/whl/cu75/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 7.5
pip install https://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CPU 版本

6. Pytorch 1.0.0

# conda
conda install pytorch==1.0.0 torchvision==0.2.1 cuda100  # CUDA 10.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda90  # CUDA 9.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda80  # CUDA 8.0
conda install pytorch-cpu==1.0.0 torchvision-cpu==0.2.1 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu100/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 10.0
pip install https://download.pytorch.org/whl/cu90/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 9.0
pip install https://download.pytorch.org/whl/cu80/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 8.0
pip install https://download.pytorch.org/whl/cpu/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CPU 版本

7. Pytorch 1.0.1

# conda
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=10.0  # CUDA 10.0
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=9.0  # CUDA 9.0
conda install pytorch-cpu==1.0.1 torchvision-cpu==0.2.2 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu100/torch-1.0.1-cp36-cp36m-win_amd64.whl torchvision==0.2.2  # CUDA 10.0
pip install https://download.pytorch.org/whl/cu90/torch-1.0.1-cp36-cp36m-win_amd64.whl torchvision==0.2.2  # CUDA 9.0
pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp36-cp36m-win_amd64.whl torchvision==0.2.2  # CPU 版本

8. Pytorch 1.1.0

# conda
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0  # CUDA 10.0
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0  # CUDA 9.0
conda install pytorch-cpu==1.1.0 torchvision-cpu==0.3.0 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp36-cp36m-win_amd64.whl torchvision==0.3.0  # CUDA 10.0
pip install https://download.pytorch.org/whl/cu90/torch-1.1.0-cp36-cp36m-win_amd64.whl torchvision==0.3.0  # CUDA 9.0
pip install https://download.pytorch.org/whl/cpu/torch-1.1.0-cp36-cp36m-win_amd64.whl torchvision==0.3.0  # CPU 版本

9. Pytorch 1.2.0

# conda
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0  # CUDA 10.0
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.2.0 torchvision==0.4.0 cpuonly  # CPU 版本
# pip
pip install torch==1.2.0+cu100 torchvision==0.4.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.0
pip install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

10. Pytorch 1.4.0

# conda
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.4.0 torchvision==0.5.0 cpuonly  # CPU 版本
# pip
pip install torch==1.4.0+cu101 torchvision==0.5.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.4.0+cu92 torchvision==0.5.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

11. Pytorch 1.5.0

# conda
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.5.0 torchvision==0.6.0 cpuonly  # CPU 版本
# pip
pip install torch==1.5.0+cu102 torchvision==0.6.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.5.0+cu92 torchvision==0.6.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

12. Pytorch 1.5.1

# conda
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.5.1 torchvision==0.6.1 cpuonly  # CPU 版本
# pip
pip install torch==1.5.1+cu102 torchvision==0.6.1+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.5.1+cu92 torchvision==0.6.1+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

13. Pytorch 1.6.0

# conda
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.6.0 torchvision==0.7.0 cpuonly  # CPU 版本
# pip
pip install torch==1.6.0+cu102 torchvision==0.7.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.6.0+cu92 torchvision==0.7.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

14. Pytorch 1.7.0

# conda
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0  # CUDA 11.0
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.7.0 torchvision==0.8.0 cpuonly  # CPU 版本
# pip
pip install torch==1.7.0+cu110 torchvision==0.8.0+cu110 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.0
pip install torch==1.7.0+cu102 torchvision==0.8.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.7.0+cu101 torchvision==0.8.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.7.0+cu92 torchvision==0.8.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.7.0+cpu torchvision==0.8.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

15. Pytorch 1.7.1

# conda
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=11.0  # CUDA 11.0
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.7.1 torchvision==0.8.2 cpuonly  # CPU 版本
# pip

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.0
pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.7.1+cu92 torchvision==0.8.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

16. Pytorch 1.8.0

# conda
conda install pytorch==1.8.0 torchvision==0.9.0 cudatoolkit=11.1  # CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.8.0 torchvision==0.9.0 cpuonly  # CPU 版本
# pip
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.1
pip install torch==1.8.0+cu102 torchvision==0.9.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.8.0+cpu torchvision==0.9.0+cpu0 -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

17. Pytorch 1.9.0

# conda
conda install pytorch==1.9.0 torchvision==0.10.0 cudatoolkit=11.1  # CUDA 11.1
conda install pytorch==1.9.0 torchvision==0.10.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.9.0 torchvision==0.10.0 cpuonly  # CPU 版本
# pip
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.1
pip install torch==1.9.0+cu102 torchvision==0.10.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.9.0+cpu torchvision==0.10.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

18. Teste se a instalação foi bem-sucedida

  • Teste de versão da CPU: Continue executando o python para entrar no ambiente interativo e execute-os separadamente import torch. import torchvisionSe nenhum erro for relatado, a instalação foi bem-sucedida.
  • Teste de versão da GPU: continue executando o python para entrar no ambiente interativo, execute-o separadamente sem import torchrelatar import torchvisionum erro e execute novamente print(torch.cuda.is_available()). Se True for exibido, a instalação foi bem-sucedida.

Insira a descrição da imagem aqui

Acho que você gosta

Origin blog.csdn.net/Wenyuanbo/article/details/119382460
Recomendado
Clasificación