每日Attention学习3——Cross-level Feature Fusion
模块出处
[link] [
](https://github.com/taozh2017/CFANet) [PR 23] Cross-level Feature Aggregation Network for Polyp Segmentation
* * *
##### 模块名称
Cross-level Feature Fusion (CFF)
* * *
##### 模块作用
双级特征融合
* * *
##### 模块结构

* * *
##### 模块代码
        import torch
import torch.nn as nn
class BasicConv2d(nn.Module):
def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, dilation=1):
    super(BasicConv2d, self).__init__()
    self.conv = nn.Conv2d(in_planes, out_planes,
                          kernel_size=kernel_size, stride=stride,
                          padding=padding, dilation=dilation, bias=False)
    self.bn = nn.BatchNorm2d(out_planes)
    self.relu = nn.ReLU(inplace=True)
def forward(self, x):
    x = self.conv(x)
    x = self.bn(x)
    return x
        类CFF继承于nn.Module;其初始化方法定义如下:def init(self,in_channels1=in_channels2=out_channels):;其初始属性设置为super类初始化;激活函数设置为nn.ReLU(inplace=True)
self.layer0    = BasicConv2d(input_channels= in_channel1,
output_channels= out_channel // 2,
kernel_size=1)
self.layer1    = BasicConv2d(input_channels= in_channel2,
output_channels= out_channel // 2,
kernel_size=1)
self.layer4 = nn.Sequential(
nn.ConvTranspose2d(in_channels*4,out_channels,kernel_size=4,stride=4,padding=0),
nn.BatchNorm2d(out_channels),
act_fn
)
这段代码实现了两个相同的卷积操作模块,并分别进行了批归一化处理后再应用激活函数。
每个模块都包含一个卷积层(kernel size of size 5),其步长设置为1,
并在卷积后对输出通道数量进行减半处理。
这种设计旨在通过逐级缩减通道数量来降低模型复杂度,
同时保持特征提取能力的同时提升模型性能。
这些模块都采用了相似的架构以实现通道数量的一半缩减,
并且在每个模块内部都应用了批归一化过程。
layer_out = Sequential(
Conv2d(out_channel // 2, out_channel, kernel_size=3, stride=1, padding=1),
BatchNorm2d(out_channel),
act_fn
)
def forward(self, x0, x1):
    x0_1  = self.layer0(x0)
    x1_1  = self.layer1(x1)
    x_3_1 = self.layer3_1(torch.cat((x0_1,  x1_1),  dim=1))    
    x_5_1 = self.layer5_1(torch.cat((x1_1,  x0_1),  dim=1))
    x_3_2 = self.layer3_2(torch.cat((x_3_1, x_5_1), dim=1))
    x_5_2 = self.layer5_2(torch.cat((x_5_1, x_3_1), dim=1))
    out   = self.layer_out(x0_1 + x1_1 + torch.mul(x_3_2, x_5_2))
    return out
        if name == 'main':
x_输入通道数量分别为批次大小(batch)、通道数(channel)、高度(height)和宽度(width)四个维度组成的二维数组
x_输入通道数量分别为批次大小(batch)、通道数(channel)、高度(height)和宽度(width)四个维度组成的二维数组
c_卷积前馈函数实例
o_经过卷积前馈函数处理后的输出张量形状为:[批次大小(batch)、输出通道数(output channel)、高度(height)和宽度(width)]
* * *
##### 原文表述
利用特征提取网络可以获得不同分辨率的多级特征。因此,有效整合多级特征非常重要,这可以提高不同尺度特征的表示能力。因此,我们提出了一个 CFF模块来融合相邻的两个特征,然后将其输入分割网络。
        