实验笔记之——Residual Dense Network for Image Super-Resolution (RDN)

本文深入探讨了RDN(Residual Dense Network)在图像超分辨率领域的应用,详细解析了其核心模块——残差密集块(RDB)的设计原理与实现代码。RDN通过密集连接和残差学习有效利用了低分辨率图像的层次特征,提高了超分辨率效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

论文链接:https://arxiv.org/pdf/1802.08797.pdf

代码链接:https://github.com/yulunzhang/RDN


python train.py -opt options/train/train_sr.json
python3 test.py -opt options/test/test_sr.json



source activate pytorch

tensorboard --logdir tb_logger/ --port 6008


http://172.20.36.203:6008/#scalars

理论

本博文主要为代码复现,所以先简单给出RDN的介绍

Dense block就是为了make full use of the hierarchical features from the original low-resolution (LR) images。通过建立更加多的跳跃链接,使得feature map之间的更深层次的特征被映射出来。

As the network depth grows, the features in each convolutional layer would be hierarchical with different receptive fields(具有不同的接受域的层次结构)作者认为,随着网络深度的增加,每个CONV层的feature具有不同接受域的层次结构。因此不能更加充分的利用信息

RD block其实就是residual block和dense block的结合版本

Contiguous memory mechanism is realized by passing the state of preceding RDB to each layer of current RDB.将前一个传递到下一个~~~就是CM机制。

 

 

 

实验

Residual dense block (RDB)的复现代码如下:

class ResidualDenseBlock_5C(nn.Module):
    '''
    Residual Dense Block
    style: 5 convs
    The core module of paper: (Residual Dense Network for Image Super-Resolution, CVPR 18)
    '''

    def __init__(self, nc, kernel_size=3, gc=32, stride=1, bias=True, pad_type='zero', \
            norm_type=None, act_type='leakyrelu', mode='CNA'):
        super(ResidualDenseBlock_5C, self).__init__()
        # gc: growth channel, i.e. intermediate channels
        self.conv1 = conv_block(nc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=act_type, mode=mode)
        self.conv2 = conv_block(nc+gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=act_type, mode=mode)
        self.conv3 = conv_block(nc+2*gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=act_type, mode=mode)
        self.conv4 = conv_block(nc+3*gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=act_type, mode=mode)
        if mode == 'CNA':
            last_act = None
        else:
            last_act = act_type
        self.conv5 = conv_block(nc+4*gc, nc, 3, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=last_act, mode=mode)

    def forward(self, x):
        x1 = self.conv1(x)
        x2 = self.conv2(torch.cat((x, x1), 1))
        x3 = self.conv3(torch.cat((x, x1, x2), 1))
        x4 = self.conv4(torch.cat((x, x1, x2, x3), 1))
        x5 = self.conv5(torch.cat((x, x1, x2, x3, x4), 1))
        return x5.mul(0.2) + x

class ResidualDenseBlockTiny_4C(nn.Module):
    '''
    Residual Dense Block
    style: 4 convs
    The core module of paper: (Residual Dense Network for Image Super-Resolution, CVPR 18)
    '''

    def __init__(self, nc, kernel_size=3, gc=16, stride=1, bias=True, pad_type='zero', \
            norm_type=None, act_type='leakyrelu', mode='CNA'):
        super(ResidualDenseBlockTiny_4C, self).__init__()
        # gc: growth channel, i.e. intermediate channels
        self.conv1 = conv_block(nc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=act_type, mode=mode)
        self.conv2 = conv_block(nc+gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=act_type, mode=mode)
        self.conv3 = conv_block(nc+2*gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=act_type, mode=mode)
        if mode == 'CNA':
            last_act = None
        else:
            last_act = act_type
        self.conv4 = conv_block(nc+3*gc, nc, 3, stride, bias=bias, pad_type=pad_type, \
            norm_type=norm_type, act_type=last_act, mode=mode)

    def forward(self, x):
        x1 = self.conv1(x)
        x2 = self.conv2(torch.cat((x, x1), 1))
        x3 = self.conv3(torch.cat((x, x1, x2), 1))
        x4 = self.conv4(torch.cat((x, x1, x2, x3), 1))
        return x4.mul(0.2) + x

 

 

 

 

 

 

 

 

 

### 关于残差密集网络(Residual Dense Network, RDN)在图像恢复中的实现与应用 #### 背景介绍 RDN 是一种专门设计用于图像复原任务的卷积神经网络模型,其核心在于通过结合残差连接和密集连接来增强特征提取能力。这种架构能够有效利用深层网络的优势,同时缓解梯度消失问题并提高训练效率[^2]。 #### 架构特点 RDN 的主要创新点在于引入了 **残差密集块(Residual Dense Blocks, RDBs)**。每个 RDB 包含多个卷积层,其中每一层都与其前一层的所有输出相连,形成密集连接模式。此外,在整个网络层面,全局残差学习机制被用来促进信息流动,从而提升模型性能[^4]。 具体来说: - 密集连接允许每层接收来自前面所有层的信息作为输入,这有助于最大化特征重用率。 - 局部残差学习应用于每个 RDB 中间,而全局残差则贯穿整个网络结构之间。 #### 实验验证 通过对多种标准测试数据集上的实验表明,相较于其他先进方法如 VDSR、LapSRN 和 MemNet 等,RDN 可以显著改善重建质量特别是在处理复杂场景下的低分辨率图片时表现出更强鲁棒性和更高精度[^3]。 例如,在真实世界的 SR 实验中,“chip”(尺寸为 244×200 像素)以及 “hatc” (大小为 133×174 像素),当面对未知降级模型的情况下,RDN 显示出了优于竞争对手的能力——即能更好地还原尖锐边界及细腻纹理特性。 以下是基于 PyTorch 的简单 RDN 实现框架: ```python import torch.nn as nn class RDB(nn.Module): def __init__(self, nDenselayer=6, growthRate=32, input_features=64): super(RDB, self).__init__() layers = [] for i in range(nDenselayer): layer = nn.Conv2d(input_features+i*growthRate, growthRate, kernel_size=3, padding=1) layers.append(layer) self.dense_layers = nn.Sequential(*layers) self.LFF = nn.Conv2d(input_features+nDenselayer*growthRate, input_features, kernel_size=1) def forward(self, x): local_features = [] for layer in self.dense_layers: out = layer(x) local_features.append(out) x = torch.cat([x, out], dim=1) LFF_out = self.LFF(torch.cat(local_features+[x],dim=1)) return LFF_out + x class RDN(nn.Module): def __init__(self, num_RDB=16, G0=64, kSize=3): super(RDN, self).__init__() # Shallow feature extraction net self.SFENet1 = nn.Conv2d(in_channels=3, out_channels=G0, kernel_size=kSize, padding=(kSize-1)//2, stride=1) self.SFENet2 = nn.Conv2d(in_channels=G0, out_channels=G0, kernel_size=kSize, padding=(kSize-1)//2, stride=1) # Redidual dense blocks and dense feature fusion self.RDBs = nn.ModuleList() for _ in range(num_RDB): self.RDBs.append(RDB()) # Global Feature Fusion self.GFF = nn.Sequential( nn.Conv2d(G0 * num_RDB, G0, kernel_size=1), nn.Conv2d(G0, G0, kernel_size=kSize, padding=(kSize-1)//2, stride=1)) # Up-sampling net self.UPNet = nn.Sequential( nn.Conv2d(G0, 256, kernel_size=3, padding=1, stride=1), nn.PixelShuffle(upscale_factor=2), nn.Conv2d(64, 3, kernel_size=3, padding=1, stride=1)) def forward(self, x): f__1 = self.SFENet1(x) x = self.SFENet2(f__1) RDBs_out = [] for rdb in self.RDBs: x = rdb(x) RDBs_out.append(x) x = self.GFF(torch.cat(RDBs_out,dim=1)) x += f__1 return self.UPNet(x) ``` 上述代码定义了一个基本版本的 RDN 结构,其中包括浅层特征提取模块(SFENet),若干个 RDB 组件组成的中间部分以及最终上采样操作完成高分辨率图像生成过程[^1]。 #### 总结 综上所述,RDN 不仅继承了传统 CNN 方法的优点,而且通过独特的内部设计克服了一些常见挑战,成为当前单幅图像超分辨领域的重要研究方向之一。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值