Skip to main content

Overview

Real-ESRGAN provides two training model classes:
  • RealESRGANModel: Full GAN training with discriminator
  • RealESRNetModel: Training without GAN losses (generator only)
Both models implement realistic degradation synthesis on GPU and support high-order degradation for training Real-World Blind Super-Resolution.

RealESRGANModel

Class Definition

Description

RealESRGANModel extends SRGANModel from BasicSR and is designed for training Real-ESRGAN with adversarial losses. It performs:
  1. Random synthesis of low-quality (LQ) images on GPU using realistic degradations
  2. Network optimization with GAN training (generator and discriminator)

Constructor Parameters

dict
required
Configuration dictionary containing training options. Key parameters include:
  • queue_size (int, default: 180): Size of training pair pool for increasing degradation diversity
  • high_order_degradation (bool): Enable two-order degradation synthesis
  • scale (int): Upsampling scale factor
  • gt_size (int): Ground truth patch size for training
  • l1_gt_usm (bool): Whether to use USM-sharpened GT for L1 loss
  • percep_gt_usm (bool): Whether to use USM-sharpened GT for perceptual loss
  • gan_gt_usm (bool): Whether to use USM-sharpened GT for GAN loss

Key Methods

feed_data()

Accepts data from dataloader and applies two-order degradations to synthesize LQ images.
dict
required
Dictionary containing:
  • gt: Ground truth high-resolution images
  • kernel1: First blur kernel
  • kernel2: Second blur kernel
  • sinc_kernel: Final sinc filter kernel
  • lq: Low-quality images (for validation/paired training)
During training with high_order_degradation=True, this method synthesizes realistic degradations including blur, resize, noise, and JPEG compression applied twice in sequence.

optimize_parameters()

Performs one optimization step for both generator and discriminator.
int
required
Current training iteration number.
This method:
  1. Optimizes the generator with pixel loss, perceptual loss, and adversarial loss
  2. Optimizes the discriminator to distinguish real vs. fake images
  3. Updates EMA (Exponential Moving Average) model if enabled

nondist_validation()

Runs validation without synthetic degradation process.

Degradation Pipeline

The model applies a two-order degradation pipeline during training: First Degradation:
  1. Blur with kernel1
  2. Random resize (up/down/keep)
  3. Add Gaussian or Poisson noise
  4. JPEG compression
Second Degradation:
  1. Optional blur with kernel2
  2. Random resize
  3. Add Gaussian or Poisson noise
  4. JPEG compression + sinc filter

Training Pair Pool

The model uses _dequeue_and_enqueue() to maintain a training pair pool that increases degradation diversity across batches.

RealESRNetModel

Class Definition

Description

RealESRNetModel extends SRModel from BasicSR and is designed for training Real-ESRGAN without GAN losses. It’s useful for:
  • Pre-training the generator before GAN training
  • Training models without adversarial losses
  • Faster convergence for initial training stages
RealESRNetModel is trained without GAN losses but uses the same degradation synthesis pipeline as RealESRGANModel.

Constructor Parameters

dict
required
Configuration dictionary. Key parameters:
  • queue_size (int, default: 180): Training pair pool size
  • high_order_degradation (bool): Enable two-order degradation synthesis
  • scale (int): Upsampling scale factor
  • gt_size (int): Ground truth patch size
  • gt_usm (bool): Apply USM sharpening to ground truth images

Key Methods

feed_data()

Same degradation synthesis as RealESRGANModel, but with optional USM sharpening on GT.
Unlike RealESRGANModel, this version applies USM sharpening directly to GT if gt_usm=True, rather than maintaining separate GT and GT_USM versions.

nondist_validation()

Validation without synthetic degradations.

Differences from RealESRGANModel

Usage Example

Training Configuration

Pre-training with RealESRNetModel

Source References

  • RealESRGANModel: realesrgan/models/realesrgan_model.py:14
  • RealESRNetModel: realesrgan/models/realesrnet_model.py:13