This project has been archived by its maintainers, and is no longer receiving any updates.
realesrgan-ncnn-py
Python Binding for realesrgan-ncnn-py with PyBind11
Real-ESRGAN aims at developing Practical Algorithms for General Image/Video Restoration. We extend the powerful ESRGAN to a practical restoration application (namely, Real-ESRGAN), which is trained with pure synthetic data. This wrapper provides an easy-to-use interface for running the pre-trained Real-ESRGAN model.
Current building status matrix
| System | Status | CPU (32bit) | CPU (64bit) | GPU (32bit) | GPU (64bit) |
|---|---|---|---|---|---|
| Linux (Clang) | — | ✅ | — | ✅ | |
| Linux (GCC) | — | ✅ | — | ✅ | |
| Windows | — | ✅ | — | ✅ | |
| MacOS | — | ✅ | — | ✅ | |
| MacOS (ARM) | — | ✅ | — | ✅ |
Usage
Python >= 3.6 (>= 3.9 in MacOS arm)
To use this package, simply install it via pip:
pip install realesrgan-ncnn-py
For Linux user:
apt install -y libomp5 libvulkan-dev
Then, import the Realesrgan class from the package:
from realesrgan_ncnn_py import Realesrgan
To initialize the model:
realesrgan = Realesrgan(gpuid: int = 0, tta_mode: bool = False, tilesize: int = 0, model: int = 0)
# model can be -1, 0, 1, 2, 3, 4; 0 for default, -1 for custom load
# 0: {"param": "realesr-animevideov3-x2.param", "bin": "realesr-animevideov3-x2.bin", "scale": 2},
# 1: {"param": "realesr-animevideov3-x3.param", "bin": "realesr-animevideov3-x3.bin", "scale": 3},
# 2: {"param": "realesr-animevideov3-x4.param", "bin": "realesr-animevideov3-x4.bin", "scale": 4},
# 3: {"param": "realesrgan-x4plus-anime.param", "bin": "realesrgan-x4plus-anime.bin", "scale": 4},
# 4: {"param": "realesrgan-x4plus.param", "bin": "realesrgan-x4plus.bin", "scale": 4}
Here, gpuid specifies the GPU device to use, tta_mode enables test-time augmentation, tilesize specifies the tile size for processing (0 or >= 32), and model specifies the num of the pre-trained model to use.
Once the model is initialized, you can use the upscale method to super-resolve your images:
Pillow
from PIL import Image
realesrgan = Realesrgan(gpuid=0)
with Image.open("input.jpg") as image:
image = realesrgan.process_pil(image)
image.save("output.jpg", quality=95)
opencv-python
import cv2
realesrgan = Realesrgan(gpuid=0)
image = cv2.imdecode(np.fromfile("input.jpg", dtype=np.uint8), cv2.IMREAD_COLOR)
image = realesrgan.process_cv2(image)
cv2.imencode(".jpg", image)[1].tofile("output_cv2.jpg")
ffmpeg
import subprocess as sp
# your ffmpeg parameters
command_out = [FFMPEG_BIN, ........]
command_in = [FFMPEG_BIN, ........]
pipe_out = sp.Popen(command_out, stdout=sp.PIPE, bufsize=10 ** 8)
pipe_in = sp.Popen(command_in, stdin=sp.PIPE)
realesrgan = Realesrgan(gpuid=0)
while True:
raw_image = pipe_out.stdout.read(src_width * src_height * 3)
if not raw_image:
break
raw_image = realesrgan.process_bytes(raw_image, src_width, src_height, 3)
pipe_in.stdin.write(raw_image)
Build
The project just only been tested in Ubuntu 18+ and Debian 9+ environments on Linux, so if the project does not work on your system, please try building it.
References
The following references were used in the development of this project:
xinntao/Real-ESRGAN-ncnn-vulkan - This project was the main inspiration for our work. It provided the core implementation of the Real-ESRGAN algorithm using the ncnn and Vulkan libraries.
Real-ESRGAN - Real-ESRGAN is an AI super resolution model, aims at developing Practical Algorithms for General Image/Video Restoration.
media2x/realsr-ncnn-vulkan-python - This project was used as a reference for implementing the wrapper. Special thanks to the original author for sharing the code.
ncnn - ncnn is a high-performance neural network inference framework developed by Tencent AI Lab.
License
This project is licensed under the BSD 3-Clause - see the LICENSE file for details.
Metadata
Release files for realesrgan-ncnn-py 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 704.2 MB
Release files / realesrgan_ncnn_py-2.0.0-cp312-none-win_amd64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp312-none-win_amd64.whl |
|---|---|
| Size | 43.9 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d8500f321271cfab07785f8a4ed8538337357d3d1332fd5cd8bfb4fdc0a9ae5a
|
|
BLAKE2b-256 checksum How to use checksums |
08c4a23692939163be6104100bec46be10555ac0e2c6a58ce0202d8853d8e365
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl |
|---|---|
| Size | 45.7 MB |
| Tags | CPython 3.12 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
166e9cc5893a4623a3542d22f71c085e663f85e12a4d4bd993533deb7a96f667
|
|
BLAKE2b-256 checksum How to use checksums |
8b827354759d49777e3201dd6307b798c74d613c482876a7be659a9eb50506ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl |
|---|---|
| Size | 51.2 MB |
| Tags | CPython 3.12 macOS 11.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
8f1aa4eaa840b4f02e57b932c1ce6074722e9dd85c68f9195d266efefbbe93b3
|
|
BLAKE2b-256 checksum How to use checksums |
7531ffe774960fe6469d520dfee3c1dfb0477e2beaa72e2fa5a80f70ebd19cac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp311-none-win_amd64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp311-none-win_amd64.whl |
|---|---|
| Size | 43.9 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
412ae180178933875b4fbcae040e0e1cae98be176d553b40f9a3c09419550dff
|
|
BLAKE2b-256 checksum How to use checksums |
5cf751a7fd21a015256d59bb2928640513870a817d800fe6757464b168c79350
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl |
|---|---|
| Size | 45.7 MB |
| Tags | CPython 3.11 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
b187dcdc3c5ed6f9f842d7fe01dff81bf8f94a72db5f2fd6789757c659c7866d
|
|
BLAKE2b-256 checksum How to use checksums |
0101881307e1bbca0af08e91fd578685f2c14db2aae66914ee23e811adec7abe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl |
|---|---|
| Size | 51.2 MB |
| Tags | CPython 3.11 macOS 11.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
d63cb1b5df7183203b5fb095a5c90e7e96e18ca544817fa099831c466ee0a94a
|
|
BLAKE2b-256 checksum How to use checksums |
d966a9775725d7c04fd98191374b7ec2a3c5d319a28d989138bdec1c1a15a908
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp310-none-win_amd64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp310-none-win_amd64.whl |
|---|---|
| Size | 43.9 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
bc9b5b6663dc2f983e2f905dcb45321e033d5af01e21cc508792f38fa2122e2d
|
|
BLAKE2b-256 checksum How to use checksums |
6e7bbccc40f69ecfff6f909891a746be5708650e5ed8afe7173018a3fee374ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl |
|---|---|
| Size | 45.7 MB |
| Tags | CPython 3.10 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
599a6bc7f296a815ebc6505079a402d036f89c6f923c67dc1eef148b6c4b280f
|
|
BLAKE2b-256 checksum How to use checksums |
a73a00d9f0f0639310f49645b241e30404c5a61299a37263f021c319df53867c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl |
|---|---|
| Size | 51.2 MB |
| Tags | CPython 3.10 macOS 11.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
4447e80da84aa039c048465d1e86ed3eff4993a36b56f7e1921d72d25409c69c
|
|
BLAKE2b-256 checksum How to use checksums |
e0b8260c28d9d173ad358b0e703dca4a78613f5cea4f0c666fe2599b41bdefa3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp39-none-win_amd64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp39-none-win_amd64.whl |
|---|---|
| Size | 43.9 MB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
af7f96d679513bf54e48a6587685c5a58ecd56e252875d8abf8383f43fb3e2de
|
|
BLAKE2b-256 checksum How to use checksums |
34a6367f3af209b70e946c9b14a8a31546c60386a3d5f85c2449c8fe79bf8866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl |
|---|---|
| Size | 45.7 MB |
| Tags | CPython 3.9 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
dbdbc141d7fe8bd2034df6c0b705b378334db97f1c0c69dd10e70ed759b2c577
|
|
BLAKE2b-256 checksum How to use checksums |
a2a831c03b3ab82c94fb309278df55ff172424d8d23e15bd0f4588b976c965a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl |
|---|---|
| Size | 51.2 MB |
| Tags | CPython 3.9 macOS 11.0+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
434bbbed7c330bfd4b59514c7d2fae13d9a9bcfa6906b7eeadf1e2b13e354ea1
|
|
BLAKE2b-256 checksum How to use checksums |
a4bc794fd2aafeb1030693d45bfb01ef81b498487cb7d08a5046dccd76293429
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp38-none-win_amd64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp38-none-win_amd64.whl |
|---|---|
| Size | 43.9 MB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
efe496bfeda8d2a5e3224147e93fffdddc8b00084647e70aae4ea7054cfea439
|
|
BLAKE2b-256 checksum How to use checksums |
635b9c3618958b53d72380a23b2cee9f822c0265a2408f9f9999240a13edbe39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl |
|---|---|
| Size | 45.7 MB |
| Tags | CPython 3.8 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
260f1d98dbc262212f6fc9a77457b5ef7c47cf0db4550a86c3b20c486117df9c
|
|
BLAKE2b-256 checksum How to use checksums |
a9cd17deac8af95aae1b03eaad7828aa0f488907a6947493372ddd3dde0102d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / realesrgan_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl
| Download URL | realesrgan_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl |
|---|---|
| Size | 51.2 MB |
| Tags | CPython 3.8 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
131f083198da6d4b5b4d01597feac759c33c5ffaf30a5be28cbc8ffa1c61e663
|
|
BLAKE2b-256 checksum How to use checksums |
047f08691d3ebfaf39a1c49238a5d150e88cc4975ee1e9f3c72b6d6880504a4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for realesrgan-ncnn-py 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.