pytorch
pytorch学习记录
夏普通
Debug Your Life.
e-mail:[email protected]
展开
-
PyTorch Error fix-RuntimeError: kind_.is_prim() INTERNAL ASSERT FAILED
报错如下:RuntimeError: kind_.is_prim() INTERNAL ASSERT FAILED at /pytorch/torch/csrc/jit/ir.cpp:904, please report a bug to PyTorch. Only prim ops are allowed to not have a registered operator but aten::_convolution doesn't have one either. We don't know if t原创 2020-07-26 21:41:04 · 1663 阅读 · 0 评论 -
pytorch之torch.utils.model_zoo.load_url()在给定URL上加载Torch序列化对象
torch.utils.model_zoo.load_url(url, model_dir=None)在给定URL上加载Torch序列化对象。通俗点说,就是通过提供的.pth文件的url地址来下载指定的.pth文件【在pytorch中.pth文件就是模型的参数文件】参数:url (string) - 要下载对象的URLmodel_dir (string, optional) - 保存对象的目录如果对象已经存在于model_dir中,则将被反序列化并返回。【也就是后面所说的——已经下载好模型的原创 2020-07-10 22:37:47 · 8541 阅读 · 2 评论 -
pytorch之torch.nn.Conv2d()函数详解
文章目录一、官方文档介绍二、torch.nn.Conv2d()函数详解参数详解参数dilation——扩张卷积(也叫空洞卷积)参数groups——分组卷积三、代码实例一、官方文档介绍官网nn.Conv2d:对由多个输入平面组成的输入信号进行二维卷积二、torch.nn.Conv2d()函数详解参数详解torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=原创 2020-07-09 22:48:24 · 198492 阅读 · 23 评论 -
Python Error fix-TypeError: _mean() got an unexpected keyword argument ‘dim‘
文章目录TypeError: _mean() got an unexpected keyword argument 'dim'报错解决【numpy中用axis和pytorch中用dim,因为一个是numpy变量一个是tensor变量】附:numpy中的axis和Pytorch中的dim参数TypeError: _mean() got an unexpected keyword argument 'dim’报错解决【numpy中用axis和pytorch中用dim,因为一个是numpy变量一个是tensor原创 2020-07-05 16:39:00 · 7860 阅读 · 2 评论 -
PyTorch Error fix-UserWarning: Legacy autograd function with non-static forward method is deprecate
报错如下:UserWarning: Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.F原创 2020-06-30 11:05:11 · 3303 阅读 · 6 评论 -
PyTorch Error fix-IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim
报错如下:IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number报错原因: pytorch版本问题loss.data[0] 是pytorch0.3.1版本代码在0.4-0.5版本的pytorch会出现警告,不会报错;在0.5版本以上的pytorch就会报错。解决方法:将loss.data[0]修改为:loss.item()...原创 2020-06-27 14:23:07 · 469 阅读 · 0 评论 -
PyTorch Error fix 汇总
文章目录1、IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim2、UserWarning: Legacy autograd function with non-static forward method is deprecate and will be removed in 1.31、IndexError: invalid index of a 0-dim tensor. Use tensor.原创 2020-06-27 14:22:40 · 572 阅读 · 1 评论 -
pytorch之torch中的几种乘法 #点乘torch.mm() #矩阵乘torch.mul(),torch.matmul() #高维Tensor相乘维度要求
文章目录1. 点乘——`torch.mul(a, b)`2. 矩阵乘2.1. 二维矩阵乘——`torch.mm(a, b)`2.2. 高维矩阵乘——`torch.matmul(a, b)`3. 高维的Tensor相乘维度要求3.1. 对于维数相同的张量3.2. 对于维数不一样的张量1. 点乘——torch.mul(a, b)点乘都是broadcast的,可以用torch.mul(a, b)实现,也可以直接用*实现。当a, b维度不一致时,会自动填充到相同维度相点乘。import torcha =原创 2020-06-21 22:34:31 · 38980 阅读 · 3 评论 -
pytorch之in-place operation #含义 #代码示例 #两种情况不能使用inplace operation
文章目录in-place含义in-place代码示例在pytorch中, 有两种情况不能使用inplace operation第一种情况: requires_grad=True 的 leaf tensor第二种情况: 求梯度阶段需要用到的张量in-place含义in-place operation在pytorch中是指改变一个tensor的值的时候,不经过复制操作,而是直接在原来的内存上改变它的值。可以称之为“原地操作符”。注意:PyTorch操作inplace版本都有后缀"_", 例如y.add_(原创 2020-06-21 21:31:10 · 1550 阅读 · 0 评论 -
pytorch之多GPU使用——#CUDA_VISIBLE_DEVICES使用 #torch.nn.DataParallel() #报错解决
文章目录1. 使用所有存在的显卡2. 指定编号使用显卡3. os.environ["CUDA_VISIBLE_DEVICES"]详解3.1. ["CUDA_VISIBLE_DEVICES"]使用3.2. 关于设置["CUDA_VISIBLE_DEVICES"]无效的解决4. torch.cuda主要函数4.1. torch.cuda.is_available()判断GPU是否可用4.2. torch.cuda.device_count()查看可用GPU数量4.3. torch.cuda.current_de原创 2020-06-14 13:27:27 · 86924 阅读 · 12 评论 -
在windows10上pip安装pytorch
文章目录一、进入官网找到适合自己的torch版本二、在pycharm终端里pip下载+安装一、进入官网找到适合自己的torch版本官网入口找到适合自己的版本,CUDA、平台、Python等,然后会自动提示“Run this command” 命令指令进行安装。我的是Python+windows10,电脑没有GPU,CUDA就选none。我用pip安裝二、在pycharm终端里pip下载+安装复制官网的安装命令,打开pycharm终端,输入命令:pip会找到和系统对应的whl文件开始下载,一原创 2020-06-06 16:12:01 · 2901 阅读 · 0 评论 -
pytorch之torch.backends.cudnn.benchmark=True——使用 GPU 来加速网络的训练
import torchtorch.backends.cudnn.enabled = Truetorch.backend.cudnn.benchmark=TruecuDNN使用非确定性算法,并且可以使用torch.backends.cudnn.enabled = False来进行禁用如果设置为torch.backends.cudnn.enabled =True,说明设置为使用使用非确定性算法然后再设置:torch.backends.cudnn.benchmark = True所以我们经常看见原创 2020-06-04 10:20:18 · 1822 阅读 · 0 评论 -
pytorch之torch.cuda.is_available()——判断GPU可用
import torchprint(torch.cuda.is_available())一般都是在命令行里:返回True说明GPU可用原创 2020-06-03 22:29:37 · 14768 阅读 · 3 评论