Inverted Residuals 的 attention版本

attention机制:

代码:

class InvertedResidual(nn.Module):
    def __init__(self, inp, oup, stride, expand_ratio, norm_layer=None):
        super(InvertedResidual, self).__init__()
        self.stride = stride
        assert stride in [1, 2]

        if norm_layer is None:
            norm_layer = nn.BatchNorm2d

        hidden_dim = int(round(inp * expand_ratio))
        self.use_res_connect = self.stride == 1 and inp == oup

        layers = []
        if expand_ratio != 1:
            # pw
            layers.append(ConvBNReLU(inp, hidden_dim, kernel_size=1, norm_layer=norm_layer))
        layers.extend([
            # dw
            ConvBNReLU(hidden_dim, hidden_dim, stride=stride, groups=hidden_dim, norm_layer=norm_layer),
            # pw-linear
            nn.Conv2d(hidden_dim, oup, 1, 1, 0, bias=False),
            norm_layer(oup),
        ])
        self.conv = nn.Sequential(*layers)
        self.conv1 = nn.Conv2d(inp, inp, 1)
        self.conv2 = nn.Conv2d(oup, oup, 1)

    def forward(self, x):
        x = self.conv1(x)
        if self.use_res_connect:
            x1 = self.conv2(x)
            return x1 + torch.mul(x1, self.conv(x))
        else:
            return self.conv(x)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
倒置残差块(Inverted Residual block)是一种主导移动网络结构设计的模块。它通过引入两个设计原则来改变经典的残差瓶颈结构,即学习倒置残差和使用线性瓶颈。这种设计改变的必要性是重新思考信息丢失和梯度混淆的风险。为了有效缓解这些问题,提出了一种新的瓶颈设计,称为sandglass block。这种设计在更高维度进行恒等映射和空间转换,以减少信息丢失和梯度混淆的影响,非常有效。在MobileNeXt中,使用了基于sandglass block的架构,堆叠了多个这样的模块。网络的输入是一个32维输出的卷积层,然后是堆叠的sandglass block,最后是全局平均池化层将二维特征图压缩为一维,并由全连接层输出每个类别的分数。123 #### 引用[.reference_title] - *1* *2* [Rethinking Bottleneck Structure for Efficient Mobile Network Design](https://blog.csdn.net/goodenough5/article/details/129852613)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *3* [MobileNext:打破常规,依图逆向改造inverted residual block | ECCV 2020](https://blog.csdn.net/lichlee/article/details/125313988)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值