XPixelGroup / BasicSR

Open Source Image and Video Restoration Toolbox for Super-resolution, Denoise, Deblurring, etc. Currently, it includes EDSR, RCAN, SRResNet, SRGAN, ESRGAN, EDVR, BasicVSR, SwinIR, ECBSR, etc. Also support StyleGAN2, DFDNet.
https://basicsr.readthedocs.io/en/latest/
Apache License 2.0
6.64k stars 1.17k forks source link

Custom Size ESRGAN Training error #329

Open purijs opened 3 years ago

purijs commented 3 years ago

Trying to train ESRGAN with custom lr/hr size, get the following error:

2020-11-12 19:13:17,807 INFO: Model [ESRGANModel] is created.
2020-11-12 19:13:18,060 INFO: Start training from epoch: 0, iter: 0
Traceback (most recent call last):
  File "train.py", line 252, in <module>
    main()
  File "train.py", line 211, in main
    model.optimize_parameters(current_iter)
  File "../basicsr/models/esrgan_model.py", line 41, in optimize_parameters
    real_d_pred = self.net_d(self.gt).detach()
  File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "../basicsr/models/archs/discriminator_arch.py", line 57, in forward
    f'Input spatial size must be 128x128, '
AssertionError: Input spatial size must be 128x128, but received torch.Size([16, 3, 32, 32]).

I've already specified 32 size in yaml file, what's the work-around for this?

hhwucn commented 3 years ago

I have the same problem.The solution is to adjust the number of linear mapping nodes of the discriminator.

ArthurT-Hub commented 3 years ago

hello! I have the same problem. How did you modify it?

ArthurT-Hub commented 3 years ago

我有同样的问题,解决方案是调整鉴别器的线性映射节点的数量。

Sorry, can you be more specific

Markfryazino commented 3 years ago

hello! I have the same problem. How did you modify it?

Currently, discriminator used in ESRGAN takes as input only images of size 128 x 128. So you have to modify basicsr/models/archs/discriminator_arch.py file so that it could be able to handle images of the size you need. To do that, remove assert on line 52 and change number of units in linear layer on line 45. It can also be useful to add some more Conv2D blocks.

ArthurT-Hub commented 3 years ago

Thank you very much!

------------------ 原始邮件 ------------------ 发件人: "xinntao/BasicSR" @.>; 发送时间: 2021年5月17日(星期一) 凌晨2:54 @.>; @.**@.>; 主题: Re: [xinntao/BasicSR] Custom Size ESRGAN Training error (#329)

hello! I have the same problem. How did you modify it?

Currently, discriminator used in ESRGAN takes as input only images of size 128 x 128. So you have to modify basicsr/models/archs/discriminator_arch.py file so that it could be able to handle images of the size you need. To do that, remove assert on line 52 and change number of units in linear layer on line 45. It can also be useful to add some more Conv2D blocks.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.