Skip to main content

Overview

RRDBNet (Residual in Residual Dense Block Network) is the primary architecture used in Real-ESRGAN models. It’s based on ESRGAN and features a deep network with residual connections and dense blocks for high-quality image super-resolution. This architecture is imported from BasicSR and used in the flagship Real-ESRGAN models.
RRDBNet is defined in basicsr.archs.rrdbnet_arch and is part of the BasicSR library, which Real-ESRGAN depends on.

Class Definition

from basicsr.archs.rrdbnet_arch import RRDBNet

model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=23,
    num_grow_ch=32,
    scale=4
)

Parameters

num_in_ch
int
default:"3"
Number of input channels. Typically 3 for RGB images.
num_out_ch
int
default:"3"
Number of output channels. Typically 3 for RGB images.
num_feat
int
default:"64"
Number of base feature channels. This determines the width of the network.
num_block
int
default:"23"
Number of RRDB (Residual in Residual Dense Block) blocks. More blocks increase model capacity and quality but also computational cost.Common configurations:
  • 23 blocks: Standard models (RealESRGAN_x4plus, RealESRGAN_x2plus)
  • 6 blocks: Lightweight anime model (RealESRGAN_x4plus_anime_6B)
num_grow_ch
int
default:"32"
Number of growth channels in dense blocks. Controls the feature growth rate within each dense block.
scale
int
default:"4"
Upsampling scale factor. Real-ESRGAN models commonly use 2 or 4.

Architecture Details

RRDBNet consists of:
  1. Shallow feature extraction: Initial convolution layer
  2. Deep feature extraction: Stack of RRDB blocks with residual scaling
  3. Upsampling module: Convolution + PixelShuffle layers
  4. Reconstruction: Final convolution to output RGB image
Each RRDB block contains:
  • Multiple dense blocks with residual connections
  • Beta residual scaling for training stability
  • Feature reuse through dense connections
The “Residual in Residual” design allows for very deep networks (23+ blocks) while maintaining stable training through multiple levels of skip connections.

Model Configurations

RealESRGAN_x4plus (Standard)

model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=23,
    num_grow_ch=32,
    scale=4
)
The flagship Real-ESRGAN model for general image super-resolution at 4× scale.

RealESRNet_x4plus (No GAN)

model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=23,
    num_grow_ch=32,
    scale=4
)
Same architecture as RealESRGAN_x4plus but trained without adversarial loss, producing smoother results.

RealESRGAN_x4plus_anime_6B (Anime)

model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=6,  # Reduced blocks for anime
    num_grow_ch=32,
    scale=4
)
Lightweight model optimized for anime images with only 6 RRDB blocks.

RealESRGAN_x2plus (2× Scale)

model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=23,
    num_grow_ch=32,
    scale=2  # 2× upsampling
)
For 2× super-resolution with the full 23-block architecture.

Usage Example

import torch
from basicsr.archs.rrdbnet_arch import RRDBNet

# Initialize RealESRGAN_x4plus model
model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=23,
    num_grow_ch=32,
    scale=4
)

# Load pretrained weights
checkpoint = torch.load('RealESRGAN_x4plus.pth')
model.load_state_dict(checkpoint['params_ema'])
model.eval()
model = model.cuda()

# Inference
with torch.no_grad():
    lr_image = torch.randn(1, 3, 128, 128).cuda()
    sr_image = model(lr_image)  # Output: (1, 3, 512, 512)

Integration with RealESRGANer

from basicsr.archs.rrdbnet_arch import RRDBNet
from realesrgan import RealESRGANer

# Create model
model = RRDBNet(
    num_in_ch=3,
    num_out_ch=3,
    num_feat=64,
    num_block=23,
    num_grow_ch=32,
    scale=4
)

# Initialize upsampler with the model
upsampler = RealESRGANer(
    scale=4,
    model_path='RealESRGAN_x4plus.pth',
    model=model,
    tile=0,
    tile_pad=10,
    pre_pad=0,
    half=True
)

# Enhance image
import cv2
img = cv2.imread('input.jpg')
output, _ = upsampler.enhance(img, outscale=4)
cv2.imwrite('output.jpg', output)

Comparison with SRVGGNetCompact

FeatureRRDBNetSRVGGNetCompact
ArchitectureDeep residual + dense blocksCompact VGG-style
Parameters~17M (23 blocks)~1-2M
QualityHighest qualityGood quality
SpeedSlowerFaster
Use caseHigh-quality imagesReal-time, video
Choose RRDBNet for maximum quality on photos and general images. Use SRVGGNetCompact for faster processing, video upscaling, or when computational resources are limited.

Source

Defined in basicsr.archs.rrdbnet_arch (BasicSR library) Used in inference_realesrgan.py for model initialization

Build docs developers (and LLMs) love