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.
- β‘ Up to 3β5Γ faster inference using TensorRT vs standard PyTorch
- π§ Supports 2x and 4x RealESRGAN models
- π Customizable output dimensions (height & width)
- πΌοΈ Includes ready-to-use scripts for image and video processing
- π Simple conversion from PyTorch to TensorRT
- π¦ Static TensorRT engine: optimized for fixed input sizes
βͺοΈ To change input size, re-export the engine
- π Dynamic TensorRT: handle varying input sizes without re-export
- π Audio transfer support: for full video enhancement pipelines
| 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 |
- Official guide: https://developer.nvidia.com/tensorrt/download
- Or via pip:
python3 -m pip install --upgrade pip
python3 -m pip install wheel
python3 -m pip install --upgrade tensorrtVerify:
>>> import tensorrt
>>> print(tensorrt.__version__)π Full guide: https://docs.nvidia.com/deeplearning/tensorrt/latest/installing-tensorrt/installing.html
pip install basicsr==1.4.2 --index-url https://pypi.org/simplePlace in:
./src/models/pretrained_models/
git clone https://github.com/NVIDIA-AI-IOT/torch2trt
cd torch2trt
python setup.py install --pluginsIf 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'
]python convert_to_trt.pypython convert_to_trt.py --height 480 --width 273python convert_to_trt.py --pretrained_model 4Xpython convert_to_trt.py --model_output_directory ./my_outputspython convert_to_trt.py --height 480 --width 273 --pretrained_model 4X --model_output_directory ./my_outputsProcess 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 4Process 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 4Left: Original | Middle: x2 Upscaled | Right: x4 Upscaled
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
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
MIT License


