Skip to content

This project provides a high-performance image and video upscaler using [RealESRGAN](https://github.com/xinntao/Real-ESRGAN), accelerated with NVIDIA TensorRT. It supports both 2x and 4x upscaling, and allows you to specify output height and width. Instructions are included for image and video upscaling using the converted models.

License

Notifications You must be signed in to change notification settings

hishambarakat16/RealESRGAN-TensorRT-Upscaler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”Ό RealESRGAN TensorRT Upscaler

This project provides a high-performance image and video upscaler using RealESRGAN, accelerated with NVIDIA TensorRT. It supports both 2x and 4x upscaling, and allows you to specify output height and width. Instructions are included for image and video upscaling using the converted models.


βœ… Features

πŸš€ Performance

  • ⚑ Up to 3–5Γ— faster inference using TensorRT vs standard PyTorch

πŸ–ΌοΈ Image & Video Upscaling

  • πŸ”§ Supports 2x and 4x RealESRGAN models
  • πŸ“ Customizable output dimensions (height & width)
  • πŸ–ΌοΈ Includes ready-to-use scripts for image and video processing

πŸ› οΈ Model Conversion

  • πŸ”„ Simple conversion from PyTorch to TensorRT
  • πŸ“¦ Static TensorRT engine: optimized for fixed input sizes
    β†ͺ️ To change input size, re-export the engine

πŸ§ͺ In Development (Upcoming Features)

  • πŸ” Dynamic TensorRT: handle varying input sizes without re-export
  • πŸ”Š Audio transfer support: for full video enhancement pipelines

🧠 Environments Used

Component Environment 1
GPU RTX 40 Series
CUDA 12.1
cuDNN 8.9.2
PyTorch 2.1.0+cu121
Python 3.10.8
OS Ubuntu 22.04

βš™οΈ Installation

1. Install TensorRT

python3 -m pip install --upgrade pip
python3 -m pip install wheel
python3 -m pip install --upgrade tensorrt

Verify:

>>> import tensorrt
>>> print(tensorrt.__version__)

πŸ“š Full guide: https://docs.nvidia.com/deeplearning/tensorrt/latest/installing-tensorrt/installing.html


2. Install basicsr

pip install basicsr==1.4.2 --index-url https://pypi.org/simple

3. Download Pretrained Models

Place in:

./src/models/pretrained_models/

4. Install torch2trt

git clone https://github.com/NVIDIA-AI-IOT/torch2trt
cd torch2trt
python setup.py install --plugins

If you see NvInfer.h: No such file or directory, update setup.py:

include_dirs=[
    trt_inc_dir(),
    '/usr/local/tensorrt/include'
],
library_dirs=[
    trt_lib_dir(),
    '/usr/local/tensorrt/targets/x86_64-linux-gnu/lib'
]

πŸ” Model Conversion

Default Conversion (2x, 512x512)

python convert_to_trt.py

Custom Size

python convert_to_trt.py --height 480 --width 273

Use 4x Model

python convert_to_trt.py --pretrained_model 4X

Custom Output Directory

python convert_to_trt.py --model_output_directory ./my_outputs

πŸ§ͺ Full Example

python convert_to_trt.py --height 480 --width 273 --pretrained_model 4X --model_output_directory ./my_outputs

πŸ–ΌοΈ 2. Image Super-Resolution

Process images with different scaling factors:

python inference_image.py --input src/samples/input.jpeg --output src/samples/output_x2.png --scale 2
python inference_image.py --input src/samples/input.jpeg --output src/samples/output_x4.png --scale 4

πŸŽ₯ 3. Video Super-Resolution

Process videos with different scaling factors:

python inference_video.py --input src/samples/input.mp4 --output src/samples/output_x2.mp4 --scale 2
python inference_video.py --input src/samples/input.mp4 --output src/samples/output_x4.mp4 --scale 4

πŸ–ΌοΈ Example Results

πŸ–ΌοΈ Image Super-Resolution Results

Left: Original | Middle: x2 Upscaled | Right: x4 Upscaled


πŸŽ₯ Video Super-Resolution Results

Input:
src/samples/sample.mp4

Outputs:
src/samples/sample_x2.mp4
src/samples/sample_x4.mp4

To view the upscaled videos:

➑️ Download and play the original video
➑️ Download and play the 2x upscaled video
➑️ Download and play the 4x upscaled video

πŸ“ Folder Structure

src/
β”œβ”€β”€ models/
β”‚   └── pretrained_models/
β”‚       β”œβ”€β”€ RealESRGAN_x2plus.pth
β”‚       └── RealESRGAN_x4plus.pth
β”œβ”€β”€ samples/
β”‚   β”œβ”€β”€ input.jpeg
β”‚   β”œβ”€β”€ input.mp4
β”‚   └── [upscaled output files]
β”œβ”€β”€ convert_to_trt.py
β”œβ”€β”€ inference_image.py
β”œβ”€β”€ inference_video.py

πŸ“œ License

MIT License

About

This project provides a high-performance image and video upscaler using [RealESRGAN](https://github.com/xinntao/Real-ESRGAN), accelerated with NVIDIA TensorRT. It supports both 2x and 4x upscaling, and allows you to specify output height and width. Instructions are included for image and video upscaling using the converted models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published