Skip to content

danhtran2mind/Anime-Super-Resolution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Anime Super Resolution πŸ–ΌοΈ

GitHub Stars Badge

huggingface-hub torch Pillow numpy torchvision diffusers gradio Built on Real-ESRGAN Built on Real-ESRGAN License: MIT

Introduction 🌟

Anime Super Resolution πŸ–ΌοΈ enhances anime-style images using a fine-tuned Real-ESRGAN model, optimized for clarity and detail. Built on the RealESRGAN_x4plus model, it leverages a private dataset of 27,052 high-resolution (1920x1080) anime frames πŸ“Έ. The project offers tools for data processing, training, inference, and an interactive Gradio demo, accessible on platforms like Colab, Kaggle, and locally πŸš€.

Key Features ✨

  • Anime-Specific Upscaling 🎨: Fine-tuned Real-ESRGAN for high-quality anime image super-resolution.

  • Large Anime Dataset πŸ“š: 27,052 high-res anime frames for robust training.

  • Interactive Gradio Demo πŸ–₯️: Easy model testing via HuggingFace-hosted interface.

  • Multi-Platform Support 🌐: Runs on Colab, Kaggle, JupyterLab, and more.

  • Data Processing Tools πŸ› οΈ: Scripts for multiscale dataset creation and meta-info generation.

  • Flexible Training/Inference βš™οΈ: Customizable configurations for training and upscaling.

  • Open-Source πŸ“–: MIT-licensed, built with PyTorch, NumPy, and Pillow.

  • Local/Cloud Compatibility ☁️: Supports local Gradio app and cloud-based execution.

Notebook

This notebook provides a step-by-step guide to finetune the Real-ESRGAN model for enhancing anime-style images. It covers data preparation, model configuration, training, and evaluation, optimized for clarity and reproducibility.

Open In Colab Open in SageMaker Open in Deepnote JupyterLab Open in Gradient Open in Binder Open In Kaggle View on GitHub

Dataset

Source

The dataset is privately extracted from anime films, comprising 27,052 images with a resolution of 1920x1080. Please read at Download Dataset if you want to use this dataset.

Data Structure

The Data Structure is

data/ πŸ“
β”œβ”€β”€ anime-images-raw/ πŸ“
β”‚   β”œβ”€β”€ frame_0001.jpg πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001_1.jpg πŸ“·
β”‚   └── ... πŸ“Έ
β”œβ”€β”€ anime-images-multiscale/ πŸ“
β”‚   β”œβ”€β”€ frame_0001T0.png πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001T1.png πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001T2.png πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001T3.png πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001_10T0.png πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001_10T1.png πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001_10T2.png πŸ“Έ
β”‚   β”œβ”€β”€ frame_0001_10T3.png πŸ“Έ
β”‚   └── ... πŸ“Έ
└── meta_info/ πŸ“
    └── meta_info_multiscale.txt πŸ“„

To proceed with the topic, please consult the section on Real-ESRGAN Data Processing for Training for comprehensive details and guidance.

Base Model

The Real-ESRGAN-Anime-finetuning model was developed by fine-tuning the pre-trained RealESRGAN_x4plus model, leveraging its robust foundation to enhance performance specifically for anime-style image super-resolution tasks.

Demonstration

Interactive Demo

Explore the interactive demo hosted on HuggingFace: HuggingFace Space Demo

Below is a screenshot of the SlimFace Demo GUI:

SlimFace Demo

Run Locally

To run the Gradio application locally at the default address localhost:7860, execute:

python apps/gradio_app.py

Installation

Clone GitHub Repository

git clone https://github.com/danhtran2mind/Anime-Super-Resolution
cd Anime-Super-Resolution

Install Dependencies (Training + Inference)

pip install -e .

Install Dependencies for Inference only

pip install -r requirements/requirements_inference.txt

Script-Driven Setup

Download Model checkpoints

  • Download only model checkpoint for Inference

    python scripts/download_ckpts.py
  • For training from Real-ESRGAN Model checkpoint

    python scripts/download_ckpts.py --base_model_only
  • For training from Real-ESRGAN-Anime-finetuning Model checkpoint

    python scripts/download_ckpts.py --full_ckpts

More detail you can read at Download Model Checkpoints.

Setup Third Party

    python scripts/setup_third_party.py

Download Dataset

    python scripts/download_datasets.py \
        --dataset_id "<huggingface_dataset_id>"
        --huggingface_token "<your_huggingface_token>"

More detail you can read at Download Dataset.

Usage

Real-ESRGAN Data Processing (for Training)

First you need see the data structure at Data Structure. Then execute below scripts to process dataset.

  • Create multiscale Folder
    python src/third_party/Real-ESRGAN/scripts/generate_multiscale_DF2K.py \
        --input ./data/anime-images-raw \
        --output ./data/anime-images-multiscale
  • Create meta_info_multiscale.txt
    python src/third_party/Real-ESRGAN/scripts/generate_meta_info.py \
    --input ./data/anime-images-raw ./data/anime-images-multiscale \
    --root ./data ./data \
    --meta_info "./data/meta_info/meta_info_multiscale.txt"

Training

Training Script

python src/anime_super_resolution/train.py \
    --config "<your_model_config_yml_path>" \
    --auto_resume

Additional Arguments

For more details and available options, refer to the Training Document.

You can see Real-ESRGAN Training, and BasicSR Training Options for more details.

Inference

Inference Script

python src/anime_super_resolution/infer.py \
    --input_path tests/test_data/input_image.png \
    --output_dir tests/test_data \
    --suffix real_esrgan_anime \
    --outscale 2 \
    --model_path ckpts/Real-ESRGAN-Anime-finetuning/net_g_latest.pth

Inference Examples

Example Image Type Image
Ex. 1 Original Image Example 1
Upscaled Image (2x) Example 1
Ex. 2 Original Image Example 2
Upscaled Image (4x) Example 2
Ex. 3 Original Image Example 2
Upscaled Image (6x) Example 2
Ex. 4 Original Image Example 2
Upscaled Image (8x) Example 2

Additional Arguments

For more details and available options, refer to the Inference Document.

Environment

SlimFace requires the following environment:

Project Credits and Resources

  • This project leverages code from:

    The Original Real-ESRGAN by GitHub at Built on Real-ESRGAN. Our own bug fixes and enhancements are available at Real-ESRGAN Enhancements.

    The Inference code by GitHub at Built on Real-ESRGAN. Our own bug fixes and enhancements are available at Real-ESRGAN Enhancements

  • You can explore more Model Hubs at:

    HuggingFace Model Hub: ai-forever Real-ESRGAN Model. Real-ESRGAN Model releases: Real-ESRGAN releases. You also download Real-ESRGAN-Anime-finetuning at Real-ESRGAN-Anime-finetuning Model

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages