用BasicSR库实现ESRGAN--下采样2倍图像重建

直接修改配置文件中的scale=2会报错。

 1. 根据报错,猜想应当是网络结构不同。到对应的rrdbnet_arch.py中读代码,发现作者有如下注释:

"""Networks consisting of Residual in Residual Dense Block, which is used
in ESRGAN.

ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks.

We extend ESRGAN for scale x2 and scale x1.
Note: This is one option for scale 1, scale 2 in RRDBNet.
We first employ the pixel-unshuffle (an inverse operation of pixelshuffle to reduce the spatial size
and enlarge the channel size before feeding inputs into the main ESRGAN architecture.

Args:
    num_in_ch (int): Channel number of inputs.
    num_out_ch (int): Channel number of outputs.
    num_feat (int): Channel number of intermediate features.
        Default: 64
    num_block (int): Block number in the trunk network. Defaults: 23
    num_grow_ch (int): Channels for each growth. Default: 32.
"""

 作者指出,已经扩展出了ESRGAN的2倍重建的功能。

这里提到了pixel-unshuffle,是pixelshuffle的反变换,是为了缩小spatial size。而后,在送进网络前,扩大了channel size。我没了解过pixelshuffle,遂查阅:

pixelshuffle是把维度(B, C*r*r, H,w) reshape成 (B, C, H*r,w*r)。那么,pixel-unshuffle则是将维度 (B, C, H*r,w*r)reshape成(B, C*r*r, H,w)。其中,作者的操作中,scale=2对应r=2;scale=1对应r=4。这样一来,输入的spatial size的缩小转换成了channel size的扩大,并且作者也在网络结构中扩大了channel size,就可以正常训练啦~

在代码中,作者也实现了对应的操作。

        if self.scale == 2:
            feat = pixel_unshuffle(x, scale=2)
        if scale == 2:
            num_in_ch = num_in_ch * 4

2. 问题出在哪儿了???是配置中还有参数需要修改吗

Yes!!!

通过在配置文件和rrdbnet_arch.py修改通道数等参数,发现在配置文件最上面直接修改scale=2的参数不能传过去,遂在network配置部分,加上一行:

scale: 2

成功传入!不报错了!

 小结:

1. 修改最上面的配置scale: 2

2. 在network structures的network_g的配置下面加一行:scale: 2

3. metrics部分的crop_border改为2

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值