### Install Real-ESRGAN via PyPI Source: https://github.com/xinntao/real-esrgan/blob/master/README.md This snippet shows how to install the Real-ESRGAN package from PyPI, which is the recommended way to get started with the library. ```Shell pip install realesrgan ``` -------------------------------- ### Start Training with a Single GPU and Auto Resume Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Starts the full training process using a single GPU and enables automatic resumption of training. This is suitable for users with limited GPU resources. ```bash python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --auto_resume ``` -------------------------------- ### Start Real-ESRGAN Training (Single-GPU, Auto-Resume) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Starts formal Real-ESRGAN training on a single GPU, allowing for automatic resumption of the training process. ```bash python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --auto_resume ``` -------------------------------- ### Example Meta Information File Content Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md An example of the content expected in the meta-information text file, listing paths to image sub-files. ```txt DF2K_HR_sub/000001_s001.png DF2K_HR_sub/000001_s002.png DF2K_HR_sub/000001_s003.png ... ``` -------------------------------- ### Start Real-ESRNet Training (Single-GPU, Debug) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Starts Real-ESRNet training on a single GPU in debug mode, using the specified configuration file. ```bash python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --debug ``` -------------------------------- ### Real-ESRGAN Installation Dependencies Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md This code block outlines the necessary steps to install Real-ESRGAN and its dependencies using pip and git. It includes cloning the repository and installing packages like basicsr, facexlib, gfpgan, and other requirements. ```bash git clone https://github.com/xinntao/Real-ESRGAN.git cd Real-ESRGAN # 安装 basicsr - https://github.com/xinntao/BasicSR # 我们使用BasicSR来训练以及推断 pip install basicsr # facexlib和gfpgan是用来增强人脸的 pip install facexlib pip install gfpgan pip install -r requirements.txt python setup.py develop ``` -------------------------------- ### Real-ESRGAN Installation and Usage Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md Provides instructions for installing Real-ESRGAN via pip and demonstrates basic command-line usage for image upscaling. It also mentions the availability of pre-trained models and the option to finetune on custom datasets. ```Shell pip install realesrgan python inference_realesrgan.py -i input_image.png -o output_image.png -n realesrgan_x4plus ``` ```Python from realesrgan import RealESRGANer model = RealESRGANer(scale=4, model_path='realesrgan_x4plus.pth', device='cuda') output, _ = model.enhance(image_path='input_image.png') # Save the output image ``` -------------------------------- ### Start Real-ESRGAN Training (Single-GPU, Debug) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Begins Real-ESRGAN training on a single GPU in debug mode, using the provided configuration file. ```bash python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --debug ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/xinntao/real-esrgan/blob/master/README.md This snippet shows how to clone the Real-ESRGAN repository and install its necessary Python packages, including BasicSR, facexlib, and gfpgan for face enhancement. ```bash git clone https://github.com/xinntao/Real-ESRGAN.git cd Real-ESRGAN # Install basicsr - https://github.com/xinntao/BasicSR # We use BasicSR for both training and inference pip install basicsr # facexlib and gfpgan are for face enhancement pip install facexlib pip install gfpgan pip install -r requirements.txt python setup.py develop ``` -------------------------------- ### Debug Training with Multiple GPUs Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Starts the training process in debug mode using multiple GPUs (specified by CUDA_VISIBLE_DEVICES) and the PyTorch launcher. This is useful for verifying the setup before full training. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --debug ``` -------------------------------- ### Official Training Real-ESRGAN (1 GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command starts the official training process for Real-ESRGAN using a single GPU. It includes options for automatic resumption of training. ```bash python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --auto_resume ``` -------------------------------- ### Start Real-ESRNet Training (Multi-GPU, Debug) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Initiates the Real-ESRNet training process using four GPUs in debug mode, specifying the configuration file and launcher. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --debug ``` -------------------------------- ### Download Pre-trained Model Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Downloads the pre-trained ESRGAN model using wget. This model is essential for starting the training process. ```bash wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth -P experiments/pretrained_models ``` -------------------------------- ### Download RealESRGAN_x4plus_netD.pth Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Downloads the pre-trained RealESRGAN_x4plus_netD model weights to the specified directory. ```bash wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models ``` -------------------------------- ### Start Real-ESRGAN Training (Multi-GPU, Auto-Resume) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Initiates formal Real-ESRGAN training across four GPUs, with the `--auto_resume` flag enabled for seamless continuation. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Debug Training with a Single GPU Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Starts the training process in debug mode using a single GPU. This is a simpler way to check if the configuration and data loading are working correctly. ```bash python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --debug ``` -------------------------------- ### Start Training with Multiple GPUs and Auto Resume Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Initiates the full training process using multiple GPUs and enables automatic resumption of training from the last checkpoint if interrupted. This is the recommended way to train the model for extended periods. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Official Training Real-ESRGAN (4 GPUs) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command starts the official training process for Real-ESRGAN using 4 GPUs. It includes options for automatic resumption of training. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Start Real-ESRGAN Training (Multi-GPU, Debug) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Launches Real-ESRGAN training across four GPUs in debug mode, utilizing the specified configuration file and PyTorch launcher. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --debug ``` -------------------------------- ### Download RealESRGAN_x4plus.pth Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Downloads the pre-trained RealESRGAN_x4plus model weights to the specified directory. ```bash wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models ``` -------------------------------- ### Real-ESRGAN Dataset Configuration (Paired Data) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Example YAML configuration for fine-tuning Real-ESRGAN with pre-paired data. It specifies the dataset type, root directories for GT and LQ images, and the meta information file. ```yml train: name: DIV2K type: RealESRGANPairedDataset dataroot_gt: datasets/DF2K # 修改为你的 gt folder 文件夹根目录 dataroot_lq: datasets/DF2K # 修改为你的 lq folder 文件夹根目录 meta_info: datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt # 修改为你自己生成的元信息txt io_backend: type: disk ``` -------------------------------- ### Running Real-ESRGAN Executable Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md Example command to run the Real-ESRGAN executable for image super-resolution. It specifies the input image, output image, and the model to be used. ```bash ./realesrgan-ncnn-vulkan.exe -i 输入图像.jpg -o 输出图像.png -n 模型名字 ``` -------------------------------- ### Start Real-ESRNet Training (Multi-GPU, Auto-Resume) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Begins formal Real-ESRNet training across four GPUs, enabling automatic resumption from the last checkpoint. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Real-ESRNet Training Configuration Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Example YAML configuration for training Real-ESRNet, specifying dataset paths, meta information, and I/O backend. ```yaml train: name: DF2K+OST type: RealESRGANDataset dataroot_gt: datasets/DF2K # modify to the root path of your folder meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # modify to your own generate meta info txt io_backend: type: disk ``` -------------------------------- ### Start Real-ESRNet Training (Single-GPU, Auto-Resume) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Initiates formal Real-ESRNet training on a single GPU, with the capability to automatically resume if interrupted. ```bash python realesrgan/train.py -opt options/train_realesrnet_x4plus.yml --auto_resume ``` -------------------------------- ### Real-ESRGAN Model Selection Example Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md Demonstrates how to use a specific Real-ESRGAN model, such as 'realesrgan-x4plus-anime', for image upscaling via the command line. ```bash ./realesrgan-ncnn-vulkan.exe -i 二次元图片.jpg -o 二刺螈图片.png -n realesrgan-x4plus-anime ``` -------------------------------- ### Real-ESRGAN Dataset Configuration (Dynamic Degradation) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Example YAML configuration for fine-tuning Real-ESRGAN with dynamically generated degradations. It specifies the dataset type, root directory for GT images, and the meta information file. ```yml train: name: DF2K+OST type: RealESRGANDataset dataroot_gt: datasets/DF2K # 修改为你的数据集文件夹根目录 meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # 修改为你自己生成的元信息txt io_backend: type: disk ``` -------------------------------- ### Finetune Real-ESRGAN (Unpaired Data, Single GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Starts the finetuning process for Real-ESRGAN on a single GPU. This command uses a specified configuration file and enables automatic resumption. ```bash python realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --auto_resume ``` -------------------------------- ### Configuration for Real-ESRGAN Finetuning (Paired Data) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Example YAML configuration for finetuning Real-ESRGAN with paired data. It details the dataset type, roots for both GT and LQ images, meta info path, and I/O backend. ```yml train: name: DIV2K type: RealESRGANPairedDataset dataroot_gt: datasets/DF2K # modify to the root path of your folder dataroot_lq: datasets/DF2K # modify to the root path of your folder meta_info: datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt # modify to your own generate meta info txt io_backend: type: disk ``` -------------------------------- ### Download Pre-trained ESRGAN Model Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md Downloads the pre-trained ESRGAN model weights, which are used to initialize the Real-ESRNet model during training. The downloaded file should be placed in the 'experiments/pretrained_models' directory. ```bash wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/ESRGAN_SRx4_DF2KOST_official-ff704c30.pth -P experiments/pretrained_models ``` -------------------------------- ### Real-ESRNet Validation Configuration Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Example YAML configuration for enabling and setting up validation during Real-ESRNet training, including dataset paths and metrics. ```yaml # Uncomment these for validation # val: # name: validation # type: PairedImageDataset # dataroot_gt: path_to_gt # dataroot_lq: path_to_lq # io_backend: # type: disk # Uncomment these for validation # validation settings # val: # val_freq: !!float 5e3 # save_img: True # metrics: # psnr: # metric name, can be arbitrary # type: calculate_psnr # crop_border: 4 # test_y_channel: false ``` -------------------------------- ### Install Pre-commit Hook Source: https://github.com/xinntao/real-esrgan/blob/master/docs/CONTRIBUTING.md Installs the pre-commit hook to automatically check code style and linting before each commit. This ensures code consistency across the project. ```shell pre-commit install ``` -------------------------------- ### Fine-tune Real-ESRGAN with Paired Data (1 GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command initiates the fine-tuning process for Real-ESRGAN using pre-paired data and a single GPU. It includes options for automatic resumption of training. ```bash python realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --auto_resume ``` -------------------------------- ### Configuration for Real-ESRGAN Finetuning (Unpaired Data) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Example YAML configuration for finetuning Real-ESRGAN with unpaired data. Specifies dataset details like name, type, data roots, meta info, and I/O backend. ```yml train: name: DF2K+OST type: RealESRGANDataset dataroot_gt: datasets/DF2K # modify to the root path of your folder meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # modify to your own generate meta info txt io_backend: type: disk ``` -------------------------------- ### Real-ESRGAN Inference Script Usage Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md Provides detailed command-line arguments and usage examples for the `inference_realesrgan.py` script. It covers input/output paths, model selection, scaling, face enhancement, and more. ```console Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]... A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance -h show this help -i --input Input image or folder. Default: inputs -o --output Output folder. Default: results -n --model_name Model name. Default: RealESRGAN_x4plus -s, --outscale The final upsampling scale of the image. Default: 4 --suffix Suffix of the restored image. Default: out -t, --tile Tile size, 0 for no tile during testing. Default: 0 --face_enhance Whether to use GFPGAN to enhance face. Default: False --fp32 Whether to use half precision during inference. Default: False --ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto ``` -------------------------------- ### Fine-tune Real-ESRGAN with Dynamic Degradation (1 GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command initiates the fine-tuning process for Real-ESRGAN using dynamic degradation generation and a single GPU. It includes options for automatic resumption of training. ```bash python realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --auto_resume ``` -------------------------------- ### Fine-tune Real-ESRGAN with Paired Data (4 GPUs) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command initiates the fine-tuning process for Real-ESRGAN using pre-paired data and 4 GPUs. It includes options for automatic resumption of training. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Debug Training Real-ESRGAN (1 GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command initiates a debug training session for Real-ESRGAN using a single GPU. It points to the training options file and enables debug mode. ```bash python realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --debug ``` -------------------------------- ### Fine-tune Real-ESRGAN with Dynamic Degradation (4 GPUs) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command initiates the fine-tuning process for Real-ESRGAN using dynamic degradation generation and 4 GPUs. It includes options for automatic resumption of training. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Configure Real-ESRNet Training Options Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This YAML file configures the training parameters for the Real-ESRNet model. Key parameters include dataset root, meta information file, and experiment name. It also includes optional validation settings. ```yml train: name: DF2K+OST type: RealESRGANDataset dataroot_gt: datasets/DF2K # 修改为你的数据集文件夹根目录 meta_info: realesrgan/meta_info/meta_info_DF2Kmultiscale+OST_sub.txt # 修改为你自己生成的元信息txt io_backend: type: disk # 取消注释这些以进行验证 # val: # name: validation # type: PairedImageDataset # dataroot_gt: path_to_gt # dataroot_lq: path_to_lq # io_backend: # type: disk # 取消注释这些以进行验证 # 验证设置 # val: # val_freq: !!float 5e3 # save_img: True # metrics: # psnr: # 指标名称,可以是任意的 # type: calculate_psnr # crop_border: 4 # test_y_channel: false ``` -------------------------------- ### Generate Meta Information Text File Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This script generates a text file containing the paths to the dataset images, which is required by the training script. It can merge paths from multiple directories and supports specifying the root directory and output meta-info file. ```bash python scripts/generate_meta_info.py --input datasets/DF2K/DF2K_HR, datasets/DF2K/DF2K_multiscale --root datasets/DF2K, datasets/DF2K --meta_info datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt ``` -------------------------------- ### Generate Meta Info for Paired Data Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This Python script generates a meta information file for paired datasets, which is required for fine-tuning Real-ESRGAN with pre-paired data. It takes the paths to the ground truth and low-quality image folders as input. ```bash python scripts/generate_meta_info_pairdata.py --input datasets/DF2K/DIV2K_train_HR_sub datasets/DF2K/DIV2K_train_LR_bicubic_X4_sub --meta_info datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt ``` -------------------------------- ### Debug Training Real-ESRGAN (4 GPUs) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This command initiates a debug training session for Real-ESRGAN using 4 GPUs. It specifies the visible CUDA devices, uses PyTorch distributed launching with 4 processes, points to the training options file, and enables debug mode. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/train_realesrgan_x4plus.yml --launcher pytorch --debug ``` -------------------------------- ### ncnn Inference for Real-ESRGAN Anime Model (Windows Example) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/anime_model.md This snippet shows how to use the ncnn executable for Real-ESRGAN anime model inference. It specifies input and output files, and the model name. Ensure you download the correct executable for your OS. ```bash ./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n realesrgan-x4plus-anime ``` -------------------------------- ### Online Demos for Real-ESRGAN Source: https://github.com/xinntao/real-esrgan/blob/master/README.md Links to online demos for Real-ESRGAN, including a Replicate demo and Colab notebooks for both general image restoration and anime video enhancement. ```APIDOC Online Demos: Replicate Demo: URL: https://replicate.com/xinntao/realesrgan Description: Interactive demo hosted on Replicate. Colab Demo (General): URL: https://colab.research.google.com/drive/1k2Zod6kSHEvraybHl50Lys0LerhyTMCo?usp=sharing Description: Google Colab notebook for Real-ESRGAN image restoration. Colab Demo (Anime Videos): URL: https://colab.research.google.com/drive/1yNl9ORUxxlL4N0keJa2SEPB61imPQd1B?usp=sharing Description: Google Colab notebook specifically for enhancing anime videos with Real-ESRGAN. ``` -------------------------------- ### Downloading Real-ESRGAN Models Source: https://github.com/xinntao/real-esrgan/blob/master/README.md Provides commands to download pre-trained Real-ESRGAN models using `wget`. These models are necessary for the inference scripts and executables to perform image upscaling. ```bash wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights ``` ```bash # download model wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights ``` -------------------------------- ### Real-ESRGAN Finetuning Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md Explains how users can finetune Real-ESRGAN on their own datasets. It provides a link to the relevant documentation for detailed instructions on the finetuning process. ```APIDOC Training.md: Finetune-Real-ESRGAN-on-your-own-dataset: - Description: Instructions for finetuning Real-ESRGAN with custom datasets. - Requirements: Python environment, Real-ESRGAN codebase, custom dataset. - Steps: 1. Prepare your dataset in the specified format. 2. Configure training parameters (e.g., learning rate, batch size, epochs). 3. Run the training script. - Output: Finetuned model weights (.pth file). ``` -------------------------------- ### Finetune Real-ESRGAN (Unpaired Data, Multi-GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Initiates the finetuning process for Real-ESRGAN using multiple GPUs. It requires a configuration file and specifies the training script and launcher. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Real-ESRGAN Executable Command Line Usage Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md This section details the command-line arguments for the Real-ESRGAN executable, allowing users to perform super-resolution tasks on images. It covers input/output paths, scaling ratios, tile sizes, model selection, GPU usage, and other operational parameters. ```console Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]... -h show this help -i input-path input image path (jpg/png/webp) or directory -o output-path output image path (jpg/png/webp) or directory -s scale upscale ratio (can be 2, 3, 4. default=4) -t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu -m model-path folder path to the pre-trained models. default=models -n model-name model name (default=realesr-animevideov3, can be realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus) -g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu -j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu -x enable tta mode" -f format output image format (jpg/png/webp, default=ext/png) -v verbose output ``` -------------------------------- ### Quick Inference with Real-ESRGAN Source: https://github.com/xinntao/real-esrgan/blob/master/README.md Demonstrates a basic command-line usage for performing image restoration using a pre-trained Real-ESRGAN model. It specifies the input image, output path, and the model used. ```Shell python inference_realesrgan.py -i inputs/test_image.png -o outputs --model_path RealESRGAN_x4plus.pth --outscale 4 --face_enhance ``` -------------------------------- ### Download Pre-trained Models (RealESRGAN_x4plus) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Downloads the RealESRGAN_x4plus model weights using wget. This model is essential for the degradation process during training. ```bash wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models ``` -------------------------------- ### Real-ESRGAN Portable Executable Files Source: https://github.com/xinntao/real-esrgan/blob/master/README.md Provides direct download links for pre-compiled Real-ESRGAN executables for Windows, Linux, and macOS. These executables utilize ncnn and Vulkan for GPU acceleration on Intel, AMD, and Nvidia GPUs. ```Shell Windows: https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-windows.zip Linux: https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip MacOS: https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-macos.zip ``` -------------------------------- ### FFmpeg Command Usage Explanations Source: https://github.com/xinntao/real-esrgan/blob/master/docs/anime_video_model.md Provides explanations for common FFmpeg command-line options used in video processing, including input file specification, video encoding, frame rate setting, and pixel format selection. ```console Usage: -i input video path -c:v video encoder (usually we use libx264) -r fps, remember to modify it to meet your needs -pix_fmt pixel format in video ``` ```console Usage: -i input video path, here we use two input streams -c:v video encoder (usually we use libx264) -r fps, remember to modify it to meet your needs -pix_fmt pixel format in video ``` -------------------------------- ### Generate Multiscale DF2K Images Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This script generates multiscale versions of HR images from the DF2K dataset, which can be used as ground truth for training. It requires the input HR images and an output directory. ```bash python scripts/generate_multiscale_DF2K.py --input datasets/DF2K/DF2K_HR --output datasets/DF2K/DF2K_multiscale ``` -------------------------------- ### Finetune Real-ESRGAN (Paired Data, Multi-GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Executes the finetuning process for Real-ESRGAN using paired data across multiple GPUs. Requires a specific configuration file and training script. ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --launcher pytorch --auto_resume ``` -------------------------------- ### Extract Subimages for Faster Processing Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training_CN.md This script extracts subimages from a dataset, which can improve I/O performance and reduce memory usage during training. It allows specifying the input directory, output directory, crop size, and step size. ```bash python scripts/extract_subimages.py --input datasets/DF2K/DF2K_multiscale --output datasets/DF2K/DF2K_multiscale_sub --crop_size 400 --step 200 ``` -------------------------------- ### Finetune Real-ESRGAN (Paired Data, Single GPU) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Runs the finetuning for Real-ESRGAN with paired data on a single GPU. This command utilizes a specified configuration file and enables auto-resume functionality. ```bash python realesrgan/train.py -opt options/finetune_realesrgan_x4plus_pairdata.yml --auto_resume ``` -------------------------------- ### Real-ESRGAN Model Zoo and Training Source: https://github.com/xinntao/real-esrgan/blob/master/README.md Information regarding the available pre-trained models (Model Zoo) and instructions for training Real-ESRGAN models. Links to specific documentation pages are provided. ```APIDOC Model Zoo: Link: docs/model_zoo.md Description: Comprehensive list and details of available pre-trained Real-ESRGAN models. Training: Link: docs/Training.md Description: Guides and instructions on how to train your own Real-ESRGAN models. ``` -------------------------------- ### Real-ESRGAN NCNN Vulkan Executable Usage Source: https://github.com/xinntao/real-esrgan/blob/master/README.md This section details the command-line usage for the portable Real-ESRGAN NCNN Vulkan executable. It outlines the various options available for input/output files, scaling, tiling, model selection, GPU usage, and more. This executable is designed for direct use without requiring a separate CUDA or PyTorch environment. ```bash ./realesrgan-ncnn-vulkan.exe -i input.jpg -o output.png -n model_name ``` ```console Usage: realesrgan-ncnn-vulkan.exe -i infile -o outfile [options]... -h show this help -i input-path input image path (jpg/png/webp) or directory -o output-path output image path (jpg/png/webp) or directory -s scale upscale ratio (can be 2, 3, 4. default=4) -t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu -m model-path folder path to the pre-trained models. default=models -n model-name model name (default=realesr-animevideov3, can be realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus) -g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu -j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu -x enable tta mode" -f format output image format (jpg/png/webp, default=ext/png) -v verbose output ``` -------------------------------- ### Run Real-ESRGAN Inference Source: https://github.com/xinntao/real-esrgan/blob/master/README.md This snippet shows how to run the Real-ESRGAN inference script with a specified model and input directory. The results are saved in the 'results' folder. ```python python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs ``` -------------------------------- ### Download Pre-trained Models (RealESRGAN_x4plus_netD) Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md Downloads the RealESRGAN_x4plus_netD model weights using wget. This is typically used for the discriminator in GAN training. ```bash wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth -P experiments/pretrained_models ``` -------------------------------- ### Real-ESRGAN API Documentation Source: https://github.com/xinntao/real-esrgan/blob/master/README_CN.md Provides an overview of the Real-ESRGAN Python API for programmatic use. It details the initialization of the `RealESRGANer` class and its `enhance` method, including parameters and return values. ```APIDOC RealESRGANer: __init__(scale: int, model_path: str, device: str = 'cuda', **kwargs): - Initializes the RealESRGANer model. - Parameters: - scale (int): The upscaling factor (e.g., 4 for 4x). - model_path (str): Path to the pre-trained model weights (.pth file). - device (str): The device to run the model on ('cuda' or 'cpu'). - Returns: An instance of RealESRGANer. enhance(image: Union[str, np.ndarray], has_ الاف: bool = False, **kwargs): - Enhances an input image using the loaded Real-ESRGAN model. - Parameters: - image (Union[str, np.ndarray]): Path to the input image or a NumPy array representing the image. - has_ الاف (bool): Whether to use GFPGAN for face enhancement (defaults to False). - Returns: - output (np.ndarray): The enhanced image as a NumPy array. - output_ الاف (np.ndarray): The enhanced face image if has_ الاف is True, otherwise None. - sf (float): The actual upscaling factor used. ``` -------------------------------- ### Generate Meta Info for Paired Data Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md A Python script to generate a meta-information text file for paired image datasets. It takes input folders for ground-truth and low-quality images. ```bash python scripts/generate_meta_info_pairdata.py --input datasets/DF2K/DIV2K_train_HR_sub datasets/DF2K/DIV2K_train_LR_bicubic_X4_sub --meta_info datasets/DF2K/meta_info/meta_info_DIV2K_sub_pair.txt ``` -------------------------------- ### Real-ESRGAN Inference Script Source: https://github.com/xinntao/real-esrgan/blob/master/README.md This Python script demonstrates the inference process for Real-ESRGAN. It supports various options such as tiling, alpha channel, grayscale images, and 16-bit images. ```python # Example usage of the inference script (inference_realesrgan.py) # python inference_realesrgan.py -i inputs -o outputs -n RealESRGAN_x4plus # Key features supported: # 1) tile options for processing large images # 2) images with alpha channel # 3) gray images # 4) 16-bit images ``` -------------------------------- ### Real-ESRGAN Specific Models Source: https://github.com/xinntao/real-esrgan/blob/master/README.md Highlights specific models tailored for anime content, including AnimeVideo-v3 and RealESRGAN_x4plus_anime_6B, with links to detailed documentation. ```APIDOC Anime Models: AnimeVideo-v3: Description: Model optimized for anime videos. Documentation: docs/anime_video_model.md RealESRGAN_x4plus_anime_6B: Description: Model designed for anime illustrations. Documentation: docs/anime_model.md Comparisons: docs/anime_comparisons.md ``` -------------------------------- ### Generate Meta Information Text File Source: https://github.com/xinntao/real-esrgan/blob/master/docs/Training.md This script generates a text file containing image paths, which is required for training. It can merge paths from multiple folders into a single meta-information file. ```bash python scripts/generate_meta_info.py --input datasets/DF2K/DF2K_HR datasets/DF2K/DF2K_multiscale --root datasets/DF2K datasets/DF2K --meta_info datasets/DF2K/meta_info/meta_info_DF2Kmultiscale.txt ``` -------------------------------- ### Real-ESRGAN BibTeX Entry Source: https://github.com/xinntao/real-esrgan/blob/master/README.md The BibTeX entry for the Real-ESRGAN paper, useful for citing the work in academic contexts. ```bibtex @InProceedings{wang2021realesrgan, author = {Xintao Wang and Liangbin Xie and Chao Dong and Ying Shan}, title = {Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data}, booktitle = {International Conference on Computer Vision Workshops (ICCVW)}, date = {2021} } ``` -------------------------------- ### Real-ESRGAN Inference Options Source: https://github.com/xinntao/real-esrgan/blob/master/docs/anime_video_model.md Explanation of command-line arguments for Real-ESRGAN inference, focusing on multi-processing and frame extraction. ```console Usage: --num_process_per_gpu The total number of process is num_gpu * num_process_per_gpu. The bottleneck of the program lies on the IO, so the GPUs are usually not fully utilized. To alleviate this issue, you can use multi-processing by setting this parameter. As long as it does not exceed the CUDA memory --extract_frame_first If you encounter ffmpeg error when using multi-processing, you can turn this option on. ``` -------------------------------- ### Real-ESRGAN Python Script Usage Source: https://github.com/xinntao/real-esrgan/blob/master/README.md This section describes the command-line interface for the Real-ESRGAN Python inference script. It covers essential arguments for specifying input/output, model selection, upscaling factors, face enhancement, and precision. The Python script offers flexibility, including the 'outscale' argument for arbitrary output sizes. ```console Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]... A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance -h show this help -i --input Input image or folder. Default: inputs -o --output Output folder. Default: results -n --model_name Model name. Default: RealESRGAN_x4plus -s, --outscale The final upsampling scale of the image. Default: 4 --suffix Suffix of the restored image. Default: out -t, --tile Tile size, 0 for no tile during testing. Default: 0 --face_enhance Whether to use GFPGAN to enhance face. Default: False --fp32 Use fp32 precision during inference. Default: fp16 (half precision). --ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto ``` ```python python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance ``` -------------------------------- ### PyTorch Inference for Real-ESRGAN Anime Model Source: https://github.com/xinntao/real-esrgan/blob/master/docs/anime_model.md This snippet demonstrates how to download the RealESRGAN_x4plus_anime_6B model and perform inference using Python. It requires the `inference_realesrgan.py` script and the model weights to be placed in the 'weights' directory. ```bash # download model wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights # inference python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs ```