torch.nn.Linear 笔记

最多支持两维,

我准备用这个代替1*1的卷积核


import torch

x = torch.randn(128, 20)  # 输入的维度是(128,20)
m = torch.nn.Linear(20, 50)  # 20,30是指维度
output = m(x)

print('m.weight.shape: ', m.weight.shape)
print('m.bias.shape:', m.bias.shape)

print('output.shape:', output.shape)

# ans = torch.mm(input,torch.t(m.weight))+m.bias 等价于下面的
ans = torch.mm(x, m.weight.t()) + m.bias
print('ans.shape:', ans.shape)

print(torch.equal(ans, output))
发布了2718 篇原创文章 · 获赞 1004 · 访问量 536万+

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/104598453