PyTorch安装:
建议首先安装一个CPU的环境,如果支持的情况下,再装一个GPU的虚拟环境
===========================================================================================
基于conda源更改的PyTorch安装:
-1. 进入命令行
-2. 执行生成.condarc文件的命令
conda config --set show_channel_urls true
-3. 将conda源.txt文件里面的内容copy到~/.condarc文件中(当前用户根目录下的.condarc文件)
-4. 执行按照命令,根据环境以及需求任选其一:
CPU版本:
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cpuonly -c pytorch
GPU版本:
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge
===========================================================================================
安装命令如下:
CPU版本安装:
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cpuonly -c pytorch
GPU版本安装:
-1. 检查当前机器是否有GPU
-2. 检查GPU的驱动是否安装好, 通过nvidia-smi命令检查
https://blog.csdn.net/kunhe0512/article/details/126265050
-3. 如果没有安装好的话,去NVIDIA官网进行驱动安装:https://www.nvidia.cn/
-4. 安装pytorch
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge
NOTE: 如果GPU的配置不是特别高,建议配置两个虚拟环境(一个CPU、一个GPU)
===========================================================================================
CPU版本的PyTorch安装命令:
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cpuonly -c pytorch
GPU版本的PyTorch安装命令:
# CUDA 10.2
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=10.2 -c pytorch
# CUDA 11.3
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge
使用pip命令进行安装(CPU版本安装):
pip install torch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 -i https://mirrors.aliyun.com/pypi/simple
===========================================================================================
(base) C:\Users\gerry_17578261252713>python
Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.10.1'
>>> torch.cuda.is_available()
False
>>>
>>> torch.rand(2,3)
tensor([[0.7895, 0.9648, 0.6547],
[0.1296, 0.4043, 0.1513]])
>>>
>>> device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
>>> a = torch.rand(2,3, device=device)
>>> a = a.to(device)
>>> a.cpu()
===========================================================================================
API文档:
torch的基本API
https://pytorch.org/docs/stable/torch.html#
torch的封装的深度学习算子API
https://pytorch.org/docs/stable/nn.html
torch的深度学习算子以函数形式的使用展示
https://pytorch.org/docs/stable/nn.functional.html
torch模型优化器相关的API
https://pytorch.org/docs/stable/optim.html
===========================================================================================