| 664 | return f1, f2, f3, f4 |
| 665 | |
| 666 | class CALayer(nn.Module): |
| 667 | def __init__(self, channel, reduction=16): |
| 668 | super(CALayer, self).__init__() |
| 669 | # global average pooling: feature --> point |
| 670 | self.avg_pool = nn.AdaptiveAvgPool2d(1) |
| 671 | # feature channel downscale and upscale --> channel weight |
| 672 | self.conv_du = nn.Sequential( |
| 673 | nn.Conv2d(channel, channel // reduction, 1, padding=0, bias=True), |
| 674 | nn.ReLU(inplace=True), |
| 675 | nn.Conv2d(channel // reduction, channel, 1, padding=0, bias=True), |
| 676 | nn.Sigmoid() |
| 677 | ) |
| 678 | |
| 679 | def forward(self, x): |
| 680 | y = self.avg_pool(x) |
| 681 | y = self.conv_du(y) |
| 682 | return x * y |
| 683 | |
| 684 | |
| 685 | class RCAB(nn.Module): |