mmagic.models.editors.real_esrgan.real_esrgan
¶
Module Contents¶
Classes¶
Real-ESRGAN model for single image super-resolution. |
- class mmagic.models.editors.real_esrgan.real_esrgan.RealESRGAN(generator, discriminator=None, gan_loss=None, pixel_loss=None, perceptual_loss=None, is_use_sharpened_gt_in_pixel=False, is_use_sharpened_gt_in_percep=False, is_use_sharpened_gt_in_gan=False, is_use_ema=True, train_cfg=None, test_cfg=None, init_cfg=None, data_preprocessor=None)[源代码]¶
Bases:
mmagic.models.editors.srgan.SRGAN
Real-ESRGAN model for single image super-resolution.
Ref: Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data, 2021.
Note: generator_ema is realized in EMA_HOOK
- 参数
generator (dict) – Config for the generator.
discriminator (dict, optional) – Config for the discriminator. Default: None.
gan_loss (dict, optional) – Config for the gan loss. Note that the loss weight in gan loss is only for the generator.
pixel_loss (dict, optional) – Config for the pixel loss. Default: None.
perceptual_loss (dict, optional) – Config for the perceptual loss. Default: None.
is_use_sharpened_gt_in_pixel (bool, optional) – Whether to use the image sharpened by unsharp masking as the GT for pixel loss. Default: False.
is_use_sharpened_gt_in_percep (bool, optional) – Whether to use the image sharpened by unsharp masking as the GT for perceptual loss. Default: False.
is_use_sharpened_gt_in_gan (bool, optional) – Whether to use the image sharpened by unsharp masking as the GT for adversarial loss. Default: False.
is_use_ema (bool, optional) – When to apply exponential moving average on the network weights. Default: True.
train_cfg (dict) – Config for training. Default: None. You may change the training of gan by setting: disc_steps: how many discriminator updates after one generate update; disc_init_steps: how many discriminator updates at the start of the training. These two keys are useful when training with WGAN.
test_cfg (dict) – Config for testing. Default: None.
init_cfg (dict, optional) – The weight initialized config for
BaseModule
. Default: None.data_preprocessor (dict, optional) – The pre-process config of
BaseDataPreprocessor
. Default: None.
- forward_tensor(inputs, data_samples=None, training=False)[源代码]¶
Forward tensor. Returns result of simple forward.
- 参数
inputs (torch.Tensor) – batch input tensor collated by
data_preprocessor
.data_samples (List[BaseDataElement], optional) – data samples collated by
data_preprocessor
.training (bool) – Whether is training. Default: False.
- 返回
result of simple forward.
- 返回类型
Tensor
- g_step(batch_outputs, batch_gt_data)[源代码]¶
G step of GAN: Calculate losses of generator.
- 参数
batch_outputs (Tensor) – Batch output of generator.
batch_gt_data (Tuple[Tensor]) – Batch GT data.
- 返回
Dict of losses.
- 返回类型
dict
- d_step_real(batch_outputs, batch_gt_data: torch.Tensor)[源代码]¶
Real part of D step.
- 参数
batch_outputs (Tensor) – Batch output of generator.
batch_gt_data (Tuple[Tensor]) – Batch GT data.
- 返回
Real part of gan_loss for discriminator.
- 返回类型
Tensor