Yolo_Nano icon indicating copy to clipboard operation
Yolo_Nano copied to clipboard

A question about FCA

Open jch-wang opened this issue 3 years ago • 0 comments

FCA in this code is the same as the python representation of the famous senet module. Why?

class FCA(nn.Module):
  
    #Module structure FCA some like
    
    def __init__(self, channels, reduce_channels):
        super(FCA, self).__init__()
        self.channels = channels


        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        self.fc = nn.Sequential(
            nn.Linear(channels, reduce_channels, bias=False),
            nn.ReLU6(inplace=True),
            nn.Linear(reduce_channels, channels, bias=False),
            nn.Sigmoid()
        )

    def forward(self, x):
        b, c, _, _ = x.size()
        out = self.avg_pool(x).view(b, c)
        out = self.fc(out).view(b, c, 1, 1)
        out = x * out.expand_as(x)
        return out
class SELayer(nn.Module):
    def __init__(self, channel, reduction=16):
        super(SELayer, self).__init__()
        self.avg_pool = nn.AdaptiveAvgPool2d(1)
        self.fc = nn.Sequential(
            nn.Linear(channel, channel // reduction, bias=False),
            nn.ReLU(inplace=True),
            nn.Linear(channel // reduction, channel, bias=False),
            nn.Sigmoid()
        )

    def forward(self, x):
        b, c, _, _ = x.size()
        y = self.avg_pool(x).view(b, c)
        y = self.fc(y).view(b, c, 1, 1)
        return x * y.expand_as(x)

jch-wang avatar Mar 11 '21 08:03 jch-wang