关于1*1 conv kernel

1x1卷积常被用于深度学习网络中,虽然在信号处理背景下可能显得不寻常。实际上,它在3D体积上进行操作,通过全输入深度进行点积,有助于减少计算复杂度并调整通道数。尽管1x1卷积在二维信号中看似简单,但在深度学习的上下文中,它能有效控制模型复杂性和维度。
摘要由CSDN通过智能技术生成


1x1 convolution. As an aside, several papers use 1x1 convolutions, as first investigated by Network in Network. Some people are at first confused to see 1x1 convolutions especially when they come from signal processing background. Normally signals are 2-dimensional so 1x1 convolutions do not make sense (it’s just pointwise scaling). However, in ConvNets this is not the case because one must remember that we operate over 3-dimensional volumes, and that the filters always extend thr

你可以使用以下代码来打印网络结构层级和输出尺寸等信息: ```python import torch import torch.nn as nn class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(3, 128, kernel_size=1, stride=1) self.conv2 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1, groups=128) self.conv3 = nn.Conv2d(256, 128, kernel_size=1, stride=1) self.conv4 = nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1, groups=256) self.conv5 = nn.Conv2d(256, 256, kernel_size=1, stride=1) self.conv6 = nn.Conv2d(256, 512, kernel_size=1, stride=1) self.avgpool = nn.AvgPool2d(kernel_size=1) self.linear = nn.Linear(512, 10) self.softmax = nn.Softmax(dim=1) def forward(self, x): x = self.conv1(x) print("Conv1*1,s=1:", x.size()) x = self.conv2(x) print("conv3*3,s=2, p=1,g=128:", x.size()) x = self.conv3(x) print("80*80*128:", x.size()) x = self.conv4(x) print("Conv1*1,s=1:", x.size()) x = self.conv5(x) print("80*80*256:", x.size()) x = self.conv6(x) print("Conv1*1,s=1:", x.size()) x = self.conv6(x) print("80*80*512:", x.size()) x = self.avgpool(x) print("Avgpool1*1*512:", x.size()) x = x.view(x.size(0), -1) x = self.linear(x) print("Linear1*10:", x.size()) x = self.softmax(x) print("Softmax:", x.size()) return x # Create an instance of the network net = Net() # Create a random input tensor with shape (batch_size, channels, height, width) input_tensor = torch.randn(1, 3, 160, 160) # Pass the input tensor through the network output_tensor = net(input_tensor) ``` 这段代码定义了一个名为`Net`的类,该类继承自`nn.Module`。在构造函数`__init__`中,我们定义了网络的各个层级,包括卷积层、池化层和全连接层。在前向传播函数`forward`中,我们打印了每个层级的输出尺寸。 你可以根据需要修改网络结构和输入张量的形状来适应你的具体情况。运行代码后,你将会看到每个层级的输出尺寸打印出来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值