Pytorch
文章平均质量分 59
得克特
深度学习 python
展开
-
torch.addcdiv 和 torch.tensor.addcdiv_
TORCH.ADDCDIVtorch.addcdiv(input, tensor1, tensor2, *, value=1, out=None) -> Tensor# input + value * tensor1 / tensor2# input, tensor1, tensor2需要是可广播的tensort = torch.randn(1, 3)t1 = torch.randn(1, 3)t2 = torch.randn(3, 1)torch.addcdiv(t, t1, t2,原创 2022-04-01 11:23:00 · 709 阅读 · 0 评论 -
torch.gather/torch.scatter
torch.gather(input, dim, index, *, sparse_grad=False, out=None) → Tensor参数:input 被索引的tensordim 索引沿着的维度index 索引的index官方给出的三维例子:out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1out[i]原创 2021-12-15 19:28:23 · 2640 阅读 · 0 评论 -
numpy和pytorch利用视图生成新对象
我们知道,numpy的array和torch的tensor在很多方面性质一样,这里以array举例,生成一个新的试图。通常而言,我们利用视图生成新的array时,每个维度对应的索引数是必须要相同,类似>>>import numpy as np>>>x = np.arange(60).reshape((3,4,5))>>>x[[1,2],[2,3],[3,4]]array([33, 59])如果索引数不同,则会出错>>>原创 2021-09-01 19:40:03 · 86 阅读 · 0 评论 -
torch.nn.CrossEntropyLoss
交叉熵损失函数torch.nn.CrossEntropyLossweight (Tensor, optional): a manual rescaling weight given to each class. If given, has to be a Tensor of size C 每个类别计算损失的权重size_average (bool, optional): Deprecated (see :attr:reduction). By default, the losses are avera原创 2021-07-25 22:09:08 · 963 阅读 · 0 评论 -
Pytorch mask:上三角和下三角
上三角 triuPytorch上三角和下三角的调用与numpy是相同的。np.triu(np.ones((5,5)),k=0) # k控制对角线开始的位置Out[25]: array([[1., 1., 1., 1., 1.], [0., 1., 1., 1., 1.], [0., 0., 1., 1., 1.], [0., 0., 0., 1., 1.], [0., 0., 0., 0., 1.]])构建一个上三角masktorch.t原创 2021-07-13 13:51:10 · 7395 阅读 · 2 评论 -
Pytorch tensor操作 gather、expand、repeat、reshape、view、permute、transpose
文章目录tensor.gathertensor.gather从原tensor中获取指定dim和指定index的数据:主要参数为index和tensorindex:index的ndims等于原tensor的ndims,index的shape等于输出的shapedim:输入index的索引值仅替换该index中对应dim的index值最终输出为替换index后在原tensor中的值import torchx = torch.arange(3, 12).view(3, 3)print(x)原创 2021-07-12 21:08:38 · 827 阅读 · 0 评论 -
通过和resnet18和resnet50理解PyTorch的ResNet模块
文章目录模型介绍resnet18模型流程总结resnet50总结resnet和resnext的框架基本相同的,这里先学习下resnet的构建,感觉高度模块化,很方便。本文算是对PyTorch源码解读之torchvision.modelsResNet代码的详细理解,另外,强烈推荐这位大神的PyTorch的教程!模型介绍resnet的模型可以直接通过torchvision导入,可以通过pretr...原创 2019-03-26 15:11:05 · 26855 阅读 · 3 评论 -
Pytorch--基础记录
文章目录Pytorchtorch.nntorch.nn.modulesPytorchtorch.nntorch.nn包含两个比较重要的模块torch.nn.modules和torch.nn.functional,如果要扩展layer,建议使用modules,因为modules保存着参数和buffer,如果不需要参数,建议使用funtional(如激活函数、pooling)。torch.nn...原创 2019-08-26 10:34:42 · 100 阅读 · 0 评论 -
torch.no_grad和验证模式
1.requires_gradrequires_gradVariable变量的requires_grad的属性默认为False,若一个节点requires_grad被设置为True,那么所有依赖它的节点的requires_grad都为True。volatile=True是Variable的另一个重要的标识,它能够将所有依赖它的节点全部设为volatile=True,其优先级比requires_......原创 2020-03-26 17:06:16 · 9368 阅读 · 3 评论