pytorch安装

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
===========================================================================================

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cts618

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值