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.bia...
最多支持两维,
我准备用这个代替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))
-
class ClassHead(nn.Module):
-
def __init__(self, inchannels=512, num_classes=2):
-
super(ClassHead, self).__init__()
-
self.num_classes = num_classes
-
self.conv1x1 = nn.Conv2d(inchannels, self.num_classes, kernel_size=(1, 1), stride=1, padding=0)
-
-
def forward(self, x):
-
out = self.conv1x1(x)
-
out = out.permute(0, 2, 3, 1).contiguous()
-
-
return out.view(out.shape[0], -1, self.num_classes)
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/104598453
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)