YoloV5/YoloV7改进---注意力机制:SRM,卷积神经网络再校准模块,性能优于SE、GE

2023-11-30 16:49:49 浏览数 (1)

1.SRM介绍

论文:https://openaccess.thecvf.com/content_ICCV_2019/papers/Lee_SRM_A_Style-Based_Recalibration_Module_for_Convolutional_Neural_Networks_ICCV_2019_paper.pdf

SRM的总体结构如 Figure 1 所示。它由两个主要组件组成:Style Pooling 和 Style Integration。Style Pooling 运算符通过汇总跨空间维度的特征响应来从每个通道提取风格特征。紧随其后的是 Style Integration 运算符,该运算符通过基于通道的操作利用风格特征来生成特定于示例的风格权重。

SRM首先通过“style pooling”从特征图的每个通道中提取风格信息,然后通过与通道无关的风格集成来估计每个通道的重新校准权重。通过将单个风格的相对重要性纳入特征图,SRM有效地增强了CNN的表示能力。

2.SRM引入到yolov5

2.1 加入common.py中:

代码语言:javascript复制
###################### SRM  attention  ####     START   by  AI&CV  ###############################

""" 
PyTorch implementation of Srm : A style-based recalibration module for 
convolutional neural networks 

As described in https://arxiv.org/pdf/1903.10829

SRM first extracts the style information from each channel of the feature maps by style pooling, 
then estimates per-channel recalibration weight via channel-independent style integration. 
By incorporating the relative importance of individual styles into feature maps, 
SRM effectively enhances the representational ability of a CNN.
"""

import torch
from torch import nn

class SRM(nn.Module):
    def __init__(self,feature, channel):
        super().__init__()
        self.cfc = nn.Conv1d(channel, channel, kernel_size=2, groups=channel,
                             bias=False)
        self.bn = nn.BatchNorm1d(channel)

    def forward(self, x):
        b, c, h, w = x.shape
        # style pooling
        mean = x.reshape(b, c, -1).mean(-1).unsqueeze(-1)
        std = x.reshape(b, c, -1).std(-1).unsqueeze(-1)
        u = torch.cat([mean, std], dim=-1)
        # style integration
        z = self.cfc(u)
        z = self.bn(z)
        g = torch.sigmoid(z)
        g = g.reshape(b, c, 1, 1)
        return x * g.expand_as(x)


###################### SRM  attention  ####     END   by  AI&CV  ###############################

by CSDN AI小怪兽 https://blog.csdn.net/m0_63774211/article/details/131553457

我正在参与2023腾讯技术创作特训营第三期有奖征文,组队打卡瓜分大奖!

0 人点赞