提高神经网络感受野ASPP(附代码)

ASPP

DeepLab: Semantic image segmentation with deep convolutional nets, atrous convolution, and fully connected CRFs.论文中提出的一种可提高感受野的技术。

空洞空间卷积池化金字塔(atrous spatial pyramid pooling (ASPP))对所给定的输入以不同采样率的空洞卷积并行采样,相当于以多个比例捕捉图像的上下文。

在这里插入图片描述
上图为deeplab v2的ASPP模块,deeplabv3中向ASPP中添加了BN层,其中空洞卷积的rate的意思是在普通卷积的基础上,相邻权重之间的间隔为rate-1, 普通卷积的rate默认为1,所以空洞卷积的实际大小为k + ( k − 1 ) ( r a t e − 1 ) k+(k-1)(rate-1)k+(k−1)(rate−1),其中k为原始卷积核大小。
在这里插入图片描述
问题:当rate接近feature map大小时,3 × 3 滤波器不是捕获全图像上下文,而是退化为简单的1 × 1 滤波器,只有滤波器中心起作用。
解决方案:Concat( 1 × 1 卷积 , 3个 3 × 3 空洞卷积 + pooled image feature)并且每个卷积核都有256个且都有BN层。

在这里插入图片描述

#without bn version
class ASPP(nn.Module):
    def __init__(self, in_channel=512, depth=256):
        super(ASPP,self).__init__()
        self.mean = nn.AdaptiveAvgPool2d((1, 1)) #(1,1)means ouput_dim
        self.conv = nn.Conv2d(in_channel, depth, 1, 1)
        self.atrous_block1 = nn.Conv2d(in_channel, depth, 1, 1)
        self.atrous_block6 = nn.Conv2d(in_channel, depth, 3, 1, padding=6, dilation=6)
        self.atrous_block12 = nn.Conv2d(in_channel, depth, 3, 1, padding=12, dilation=12)
        self.atrous_block18 = nn.Conv2d(in_channel, depth, 3, 1, padding=18, dilation=18)
        self.conv_1x1_output = nn.Conv2d(depth * 5, depth, 1, 1)
 
    def forward(self, x):
        size = x.shape[2:]
 
        image_features = self.mean(x)
        image_features = self.conv(image_features)
        image_features = F.upsample(image_features, size=size, mode='bilinear')
 
        atrous_block1 = self.atrous_block1(x)
        atrous_block6 = self.atrous_block6(x)
        atrous_block12 = self.atrous_block12(x)
        atrous_block18 = self.atrous_block18(x)
 
        net = self.conv_1x1_output(torch.cat([image_features, atrous_block1, atrous_block6,
                                              atrous_block12, atrous_block18], dim=1))
        return net

转载:https://blog.csdn.net/qq_36530992/article/details/102628455

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liiiiiiiiiiiiike

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值