Shortcuts

mmedit.models.editors.srgan.srgan

Module Contents

Classes

SRGAN

SRGAN model for single image super-resolution.

class mmedit.models.editors.srgan.srgan.SRGAN(generator, discriminator=None, gan_loss=None, pixel_loss=None, perceptual_loss=None, train_cfg=None, test_cfg=None, init_cfg=None, data_preprocessor=None)[源代码]

Bases: mmedit.models.base_models.BaseEditModel

SRGAN model for single image super-resolution.

Ref: Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network.

参数
  • generator (dict) – Config for the generator.

  • discriminator (dict) – Config for the discriminator. Default: None.

  • gan_loss (dict) – Config for the gan loss. Note that the loss weight in gan loss is only for the generator.

  • pixel_loss (dict) – Config for the pixel loss. Default: None.

  • perceptual_loss (dict) – Config for the perceptual loss. Default: None.

  • train_cfg (dict) – Config for training. Default: None.

  • 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_train(inputs, data_samples=None, **kwargs)[源代码]

Forward training. Losses of training is calculated in train_step.

参数
  • inputs (torch.Tensor) – batch input tensor collated by data_preprocessor.

  • data_samples (List[BaseDataElement], optional) – data samples collated by data_preprocessor.

返回

Result of forward_tensor with training=True.

返回类型

Tensor

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

if_run_g()[源代码]

Calculates whether need to run the generator step.

if_run_d()[源代码]

Calculates whether need to run the discriminator step.

g_step(batch_outputs: torch.Tensor, batch_gt_data: torch.Tensor)[源代码]

G step of GAN: Calculate losses of generator.

参数
  • batch_outputs (Tensor) – Batch output of generator.

  • batch_gt_data (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 (Tensor) – Batch GT data.

返回

Real part of gan_loss for discriminator.

返回类型

Tensor

d_step_fake(batch_outputs: torch.Tensor, batch_gt_data)[源代码]

Fake part of D step.

参数
  • batch_outputs (Tensor) – Batch output of generator.

  • batch_gt_data (Tensor) – Batch GT data.

返回

Fake part of gan_loss for discriminator.

返回类型

Tensor

g_step_with_optim(batch_outputs: torch.Tensor, batch_gt_data: torch.Tensor, optim_wrapper: mmengine.optim.OptimWrapperDict)[源代码]

G step with optim of GAN: Calculate losses of generator and run optim.

参数
  • batch_outputs (Tensor) – Batch output of generator.

  • batch_gt_data (Tensor) – Batch GT data.

  • optim_wrapper (OptimWrapperDict) – Optim wrapper dict.

返回

Dict of parsed losses.

返回类型

dict

d_step_with_optim(batch_outputs: torch.Tensor, batch_gt_data: torch.Tensor, optim_wrapper: mmengine.optim.OptimWrapperDict)[源代码]

D step with optim of GAN: Calculate losses of discriminator and run optim.

参数
  • batch_outputs (Tensor) – Batch output of generator.

  • batch_gt_data (Tensor) – Batch GT data.

  • optim_wrapper (OptimWrapperDict) – Optim wrapper dict.

返回

Dict of parsed losses.

返回类型

dict

extract_gt_data(data_samples)[源代码]

extract gt data from data samples.

参数

data_samples (list) – List of EditDataSample.

返回

Extract gt data.

返回类型

Tensor

train_step(data: List[dict], optim_wrapper: mmengine.optim.OptimWrapperDict) Dict[str, torch.Tensor][源代码]

Train step of GAN-based method.

参数
  • data (List[dict]) – Data sampled from dataloader.

  • optim_wrapper (OptimWrapper) – OptimWrapper instance used to update model parameters.

返回

A dict of tensor for logging.

返回类型

Dict[str, torch.Tensor]

Read the Docs v: latest
Versions
master
latest
stable
zyh-doc-notfound-extend
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.