pytorch
梅文化_2019
这个作者很懒,什么都没留下…
展开
-
pytorch1.4+tensorboard不显示graph计算图的问题
电脑安装的pytoch版本为1.4,tensorboard无法显示计算图graph,但可以显示scalar。经过多方查证为pytorch版本问题,目前graph显示仅支持到pytorch1.3。处理如下:(1)卸载当前的pytorch并安装低版本1.3.1版本卸载当前的高版本,cmd中输入:pip uninstall torch安装低版本,采用离线安装的方式。从连接https://...原创 2020-04-23 22:36:17 · 1192 阅读 · 1 评论 -
pytorch: where、gather函数
**一、where函数**torch.where(condition,x,y)out = x,if condition is 1= y ,if condition is 0In [29]: cond = torch.rand(2,2)In [30]: condOut[30]:tensor([[0.1326, 0.4126], [0.7093, 0.5339]])...原创 2019-10-24 14:42:31 · 4513 阅读 · 0 评论 -
pytorch:属性统计
**一、求范数**torch.norm(p,dim)In [1]: import torchIn [2]: a = torch.full([8],1)In [3]: aOut[3]: tensor([1., 1., 1., 1., 1., 1., 1., 1.])In [4]: b = a.view(2,4)In [5]: bOut[5]:tensor([[1., 1...原创 2019-10-24 11:44:08 · 693 阅读 · 0 评论 -
pytorch:tensor的运算
**一、加减乘除**torch.add / torch.sub / torch.mul / torch.div分别为矩阵对应元素的加减乘除与使用符号±*/功能相同//表示整除In [1]: import torchIn [2]: a = torch.rand(3,4)In [3]: b = torch.rand(4)In [4]: a+bOut[4]:tensor([...原创 2019-10-22 14:40:43 · 2581 阅读 · 0 评论 -
pytorch拼接与拆分
**一、拼接**cat/stackcat在指定的维度上进行连接;stack创建了新的维度进行连接。In [1]: import torchIn [2]: a = torch.rand(4,32,8)In [3]: b = torch.rand(5,32,8)In [4]: torch.cat([a,b],dim=0).shapeOut[4]: torch.Size([9,...原创 2019-10-22 12:38:05 · 3068 阅读 · 0 评论 -
pytorch维度变换
一、view/reshapeIn [1]: import torchIn [2]: a = torch.rand(4,1,28,28)In [3]: a.shapeOut[3]: torch.Size([4, 1, 28, 28])In [4]: a.view(4,28*28)Out[4]:tensor([[0.3060, 0.2680, 0.3763, ..., 0.659...原创 2019-10-22 11:20:30 · 507 阅读 · 0 评论 -
pytorch的索引与切片
**一、从左边开始索引**In [12]: a = torch.rand(4,3,28,28)In [13]: a.shapeOut[13]: torch.Size([4, 3, 28, 28])In [14]: a[0].shapeOut[14]: torch.Size([3, 28, 28])In [15]: a[0,0].shapeOut[15]: torch.Siz...原创 2019-10-21 18:06:32 · 540 阅读 · 0 评论 -
pytorch创建tensor
**一、import from numpy**In [40]: a = np.array([2,3.3])In [41]: aOut[41]: array([2. , 3.3])In [42]: b = torch.from_numpy(a)In [43]: bOut[43]: tensor([2.0000, 3.3000], dtype=torch.float64)In...原创 2019-10-21 16:59:28 · 2897 阅读 · 0 评论 -
pytorch tensor的数据类型
一、维度为0的标量一般用于loss计算In [1]: import torchIn [2]: a = torch.tensor(1.)#维度为0In [3]: b = torch.tensor(1.3)In [4]: c = torch.tensor(2.2)In [5]: a.shape,b.shape,c.shapeOut[5]: (torch.Size([]), tor...原创 2019-10-21 15:44:26 · 207 阅读 · 0 评论