LINEAR LAYERS

博客主要介绍了Linear层,并给出了两个示例。Linear层在信息技术领域有重要应用,示例有助于理解其具体使用方式。

Linear层
在这里插入图片描述
Examples1

import torch

x = torch.randn(128, 20)         # 输入的维度是(128,20)
m = torch.nn.Linear(20, 30)      # 维度 20,30
output = m(x)
print('m.weight.shape:\n ', m.weight.shape)
print('m.bias.shape:\n', m.bias.shape)
print('output.shape:\n', output.shape)

ans = torch.mm(x, m.weight.t()) + m.bias
print('ans.shape:\n', ans.shape)

print(torch.equal(ans, output))


结果:
"""m.weight.shape:
  torch.Size([30, 20])
  
m.bias.shape:
 torch.Size([30])
 
output.shape:
 torch.Size([128, 30])
 
ans.shape:
 torch.Size([128, 30])

Examples2:

>>> m = nn.Linear(20, 30)
>>> input = torch.randn(128, 20)
>>> output = m(input)
>>> print(output.size())
torch.Size([128, 30])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值