Skip to main content

Overview

The inference_realesrgan.py script is the main tool for performing image super-resolution with Real-ESRGAN. It supports various models, configurations, and advanced features like face enhancement and tile processing.

Quick Start

1

Basic Usage

Run Real-ESRGAN with default settings:
python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs
This will process all images in the inputs folder using the RealESRGAN_x4plus model and save results to the results folder.
2

Custom Output

Specify input and output paths:
python inference_realesrgan.py -n RealESRGAN_x4plus -i input.jpg -o output_folder
3

View Results

Enhanced images will be saved with the _out suffix by default (e.g., image_out.png).

Command-Line Arguments

Required Arguments

-i, --input
string
default:"inputs"
Input image file or folder containing images to process
-n, --model_name
string
default:"RealESRGAN_x4plus"
Model to use for super-resolution. Available models:
  • RealESRGAN_x4plus - General purpose 4x upscaling
  • RealESRNet_x4plus - ESRGAN model without GAN
  • RealESRGAN_x4plus_anime_6B - Optimized for anime images
  • RealESRGAN_x2plus - 2x upscaling model
  • realesr-animevideov3 - Anime video model (XS size)
  • realesr-general-x4v3 - General purpose with denoise control

Output Options

-o, --output
string
default:"results"
Output folder for enhanced images
-s, --outscale
float
default:"4"
Final upsampling scale of the image. Can be any value (e.g., 3.5).The model performs its native upscaling, then resizes to the target scale using LANCZOS4 interpolation.
--suffix
string
default:"out"
Suffix added to restored images (e.g., image_out.png). Set to empty string for no suffix.
--ext
string
default:"auto"
Output image format: auto, jpg, or png
  • auto: Uses the same extension as input
  • RGBA images are always saved as PNG

Performance Options

-t, --tile
integer
default:"0"
Tile size for processing large images. Set to 0 to disable tiling.
Use tiling if you encounter CUDA out of memory errors. Recommended values: 256, 400, or 512.
python inference_realesrgan.py -n RealESRGAN_x4plus -i input.jpg --tile 400
--tile_pad
integer
default:"10"
Padding size for each tile to reduce edge artifacts
--pre_pad
integer
default:"0"
Pre-padding size at each border of the image
--fp32
flag
Use FP32 (full precision) instead of FP16 (half precision) during inferenceIncreases memory usage but may improve quality slightly. Default is FP16.
-g, --gpu-id
integer
default:"None"
GPU device to use (e.g., 0, 1, 2 for multi-GPU systems)

Advanced Options

--face_enhance
flag
Enable GFPGAN face enhancement integrationAutomatically enhances faces in the image using GFPGAN v1.3
python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
-dn, --denoise_strength
float
default:"0.5"
Denoise strength for the realesr-general-x4v3 model only
  • 0: Weak denoise (keep noise)
  • 1: Strong denoise ability
  • Values between 0 and 1 interpolate between the two extremes
--model_path
string
default:"None"
Custom model path. Usually not needed as models are auto-downloaded to the weights folder.
--alpha_upsampler
string
default:"realesrgan"
Upsampler for alpha channels in RGBA images: realesrgan or bicubic

Common Usage Examples

Example 1: Basic Upscaling

python inference_realesrgan.py -n RealESRGAN_x4plus -i input.jpg

Example 2: Custom Scale with Face Enhancement

python inference_realesrgan.py -n RealESRGAN_x4plus -i input.jpg --outscale 3.5 --face_enhance

Example 3: Batch Processing with Tiling

python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs_folder -o results --tile 400 --tile_pad 10

Example 4: Denoise Control

python inference_realesrgan.py -n realesr-general-x4v3 -i input.jpg --denoise_strength 0.8

Model Downloads

Models are automatically downloaded on first use. Manual download URLs:
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights

Error Handling

CUDA Out of Memory ErrorIf you encounter this error:
RuntimeError: CUDA out of memory
Try the following solutions:
  1. Use the --tile option with a smaller value (e.g., 256 or 400)
  2. Enable --fp32 if using half precision
  3. Use a smaller --outscale value
  4. Process images one at a time instead of batch processing

Supported Image Formats

The inference script supports:
  • Color spaces: RGB, RGBA (with alpha channel), Grayscale
  • Bit depths: 8-bit, 16-bit images
  • Formats: JPG, PNG, WebP, and other common formats

Next Steps

General Images

Learn model selection for real-world photos

Anime Images

Optimize for anime and illustration content

Face Enhancement

Integrate GFPGAN for better face restoration

Video Processing

Process video files frame by frame

Build docs developers (and LLMs) love