inference_realesrgan.py
Command-line script for upsampling images using Real-ESRGAN models.Usage
Arguments
str
default:"inputs"
Input image or folder path
str
default:"RealESRGAN_x4plus"
Model name to use for inferenceAvailable models:
RealESRGAN_x4plus- General 4x upsamplingRealESRNet_x4plus- 4x upsampling without GANRealESRGAN_x4plus_anime_6B- Anime images 4xRealESRGAN_x2plus- General 2x upsamplingrealesr-animevideov3- Anime video 4xrealesr-general-x4v3- General purpose 4x with denoise control
str
default:"results"
Output folder path
float
default:"0.5"
Denoise strength. Range: 0 (weak denoise, keep noise) to 1 (strong denoise ability)Only used for the
realesr-general-x4v3 modelfloat
default:"4"
The final upsampling scale of the image
str
default:"None"
Optional custom model path. Usually not needed as models are downloaded automatically
str
default:"out"
Suffix of the restored image filename
int
default:"0"
Tile size for processing. 0 means no tiling. Use tiling to avoid out-of-memory errors with large images
int
default:"10"
Tile padding size to reduce border artifacts
int
default:"0"
Pre-padding size at each border
bool
Use GFPGAN to enhance faces in the image (flag, no value needed)
bool
Use fp32 (full) precision during inference. Default is fp16 (half precision)
str
default:"realesrgan"
The upsampler for alpha channels (transparency)Options:
realesrgan | bicubicstr
default:"auto"
Output image extensionOptions:
auto | jpg | pngauto uses the same extension as the inputint
default:"None"
GPU device to use. Can be 0, 1, 2, etc. for multi-GPU systems
Examples
Memory Management:
If you encounter CUDA out of memory errors, try using the
--tile option with a smaller tile size (e.g., -t 200 or -t 400). Tiling processes the image in smaller chunks at the cost of slightly slower processing.File Formats:
RGBA images (with transparency) are automatically saved as PNG regardless of the
--ext setting to preserve the alpha channel.inference_realesrgan_video.py
Command-line script for upsampling videos using Real-ESRGAN models. Optimized for anime videos.Usage
Arguments
str
default:"inputs"
Input video, image, or folder path
str
default:"realesr-animevideov3"
Model name to use for inferenceAvailable models:
realesr-animevideov3- Optimized for anime videos (default)RealESRGAN_x4plus_anime_6B- Anime images/videos 4xRealESRGAN_x4plus- General 4x upsamplingRealESRNet_x4plus- 4x upsampling without GANRealESRGAN_x2plus- General 2x upsamplingrealesr-general-x4v3- General purpose 4x with denoise control
str
default:"results"
Output folder path
float
default:"0.5"
Denoise strength. Range: 0 (weak denoise, keep noise) to 1 (strong denoise ability)Only used for the
realesr-general-x4v3 modelfloat
default:"4"
The final upsampling scale of the video
str
default:"out"
Suffix of the restored video filename
int
default:"0"
Tile size for processing. 0 means no tiling. Use tiling to avoid out-of-memory errors
int
default:"10"
Tile padding size to reduce border artifacts
int
default:"0"
Pre-padding size at each border
bool
Use GFPGAN to enhance faces in the video (flag, no value needed)Note: Automatically disabled for anime models
bool
Use fp32 (full) precision during inference. Default is fp16 (half precision)
float
default:"None"
FPS of the output video. If not specified, uses the input video’s FPS
str
default:"ffmpeg"
Path to the ffmpeg binary
bool
Extract frames to disk before processing (flag, no value needed). Can be useful for certain workflows
int
default:"1"
Number of processes to spawn per GPU for parallel processing
str
default:"realesrgan"
The upsampler for alpha channels (transparency)Options:
realesrgan | bicubicstr
default:"auto"
Image extension when processing image foldersOptions:
auto | jpg | pngExamples
Performance Warning:
If you are generating videos larger than 4K resolution, processing will be very slow due to I/O speed limitations. It is highly recommended to decrease the
--outscale value.Multi-GPU Processing:
The script automatically detects available GPUs and can process video segments in parallel. Use
--num_process_per_gpu to control how many processes run per GPU. For example, with 2 GPUs and --num_process_per_gpu 2, a total of 4 processes will run in parallel.FLV Format:
If the input is a
.flv file, the script automatically converts it to .mp4 using ffmpeg before processing.Audio Preservation:
The script automatically preserves the audio track from the input video in the output video.
Helper Classes
The video inference script includes two helper classes:Reader
Handles reading frames from videos, images, or folders. Supports streaming from video files using ffmpeg. Methods:get_resolution()- Returns (height, width) of the inputget_fps()- Returns the FPS of the videoget_audio()- Returns the audio streamget_frame()- Returns the next frameclose()- Closes the stream reader
Writer
Handles writing frames to output video using ffmpeg with H.264 encoding. Methods:write_frame(frame)- Writes a frame to the output videoclose()- Finalizes and closes the output video