No project description provided
Project description
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.
Current building status matrix
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, **_kwargs)
# 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for realesrgan_ncnn_py-1.0.0.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ec4a2ece9f8a9512834a0d0c57b00fc4ac193a9575e4be06d0f9adc0fbf00f1 |
|
MD5 | 9f890236323b39507d0cb3ff6ce371a9 |
|
BLAKE2b-256 | 33b29165e4d48a07e80eff22db5392b88ed2edbbbb3c2c655234d9be10065278 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4b7e77a4a684a593321882d06dd9615ad4d733edca0ad5e77c6a6f1c1fad936 |
|
MD5 | fc3dde8196bf7a280361752046925114 |
|
BLAKE2b-256 | 595b6b26fc11ce3f64e34c20e5b3f155158e12c2ac01c42b8a042f6be26a45b9 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcf9a093804ac4f51fa3f250735686e3f4932dfeec412d83e51710e95129fc62 |
|
MD5 | 54d363065a5a437a942eacd748961dda |
|
BLAKE2b-256 | 2ace24e70f12f679308157c5cc8091061db46055d970e0687fd1623c6aecddf5 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e36a91aa3e46562e01680a7120aaf7355e831ebb3abb98b50ca10fadaa4a0fd5 |
|
MD5 | 3602e5ceaa0e2ca214686cc86671da2d |
|
BLAKE2b-256 | 0dee4ad8de46413e16ca2cbb8a219cc6a8de47337bfd26fcac4efcf1d89727ba |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a4dab440717220b350dacc8159a948bf0243690810a843255ee25ed8a2856d7 |
|
MD5 | 0b81a806f6c934611a6a35820a3d333b |
|
BLAKE2b-256 | 5d918dd732222da90669f0194fde7c2f9413fbd7da21de425b22b4b1ae57b588 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bf468be3e11e4267f42f9571ffdb8ad4a8f93406eeb00af7c85a8e3ec9375e4 |
|
MD5 | 1ce2cc0a13100fdd9d0e37075baa6f3f |
|
BLAKE2b-256 | abc7706326997bf066de3fa265798227779b29f6870d1df7a03e8e2e0e29f8a4 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0727575018d35377058b24b32ae602a22e87345e677a85269de42f52b328f5f0 |
|
MD5 | 69f12ce738fd88967bb713633671680c |
|
BLAKE2b-256 | 19c24f0597c047de05768179610be5770a2c18a388a6b19d6e51e28abbf7df59 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16cb0c2da2545660fd1870cb7c07938beceb4532427a1bc3745c5129b1011f01 |
|
MD5 | c53f68d4eedc9293454848f86c1d85cc |
|
BLAKE2b-256 | 2be9fd87292e2b26ff4c73625707e087696a532d6aaaea239fc94a9309171726 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f39f400673f44d980e38c2d1350008ec16a5a0f7b3514bc0f1d4247e8eec6183 |
|
MD5 | 33913e263ee2be38924ba006ae0dc152 |
|
BLAKE2b-256 | 2910a69f5f5cccf88de27d32e72c89700883ac7a8d7b6b4b320be8bc91971cfe |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31bf57d758a4eca87612245244c4640ba3c6c28f0fda21cde3bc22187c241721 |
|
MD5 | 02e0f37c5e2a3b5fe26059c95412e7e6 |
|
BLAKE2b-256 | fb42e16ef3c0c06d4a7936bd059b8f40d278561bf0f068d743baef27a095e60b |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdab528e61a4e79126bdbdfb00d04255462cc0a717642e3bc8adba29cb5f8cbc |
|
MD5 | 7b33921e31bb3bc564492cf2979fc536 |
|
BLAKE2b-256 | 6345e1c419a6c26e8f3566441795fbdfa3f2d4b5bc8c2984c524af55e256d980 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48ed1f7016d7cd9a3eb4b9b25b77eb1a5af6746de3a190f838dd7a6ff6e14d2f |
|
MD5 | f53fac43d74c823635ba7677c89468e3 |
|
BLAKE2b-256 | f5b12cb67fec699a20d50a55dca75ccfc93f5b355217d25a3ccd3e7cfb54c548 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b59f766e4a806e98370f1e21a7ad0371d31146ec193a568b87ddd8968e17917 |
|
MD5 | 3f592dda375daaa44badd3c36e03b84d |
|
BLAKE2b-256 | c74175ab13b3be0c061a8b2133d93b6e523c4d5451f23dbcb4b696ce67902538 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 729cf96c62c49b87a6849cf26cc9773dafc928f4a2fbd583fea3cba98c30721c |
|
MD5 | bd5f119edb2aedfe71e652bb86e0640c |
|
BLAKE2b-256 | 92449edb41702d1451c1c97dfe70b900f61245accfe3b2eb8adc691ca388af55 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36280fad965246718ccbf5d3c1bbaff3e3fd28debbfc39a939c2d033eda4df9c |
|
MD5 | f69227dd266f9ecae93814c8a9da0e90 |
|
BLAKE2b-256 | d8f0189c0aa348493e3e21a138fefd6036f8e0c0831e9c57e951a0fdf4dfe183 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05e34bfb0b6690ebd52707803a8e912c2ee7e55c0a6c67b93f1a376b2639cca1 |
|
MD5 | 403ea426ecbc4276794958770518835a |
|
BLAKE2b-256 | cd3bd6112f73abac68cc7455f0a375ef3b1cf65a8c0582879580f602d2eac8fd |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9172b337c1fc48000ed5b19e6075484a53099bd97bfd3b0233ee71e4cab9f08 |
|
MD5 | 599dd5fda126af7eceb01b1055c7fe5d |
|
BLAKE2b-256 | 815c8b027beddc831da93163400b62ca8de6d6f9941173c27eeea4bc00e02cc8 |
Hashes for realesrgan_ncnn_py-1.0.0.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c03670a8db0009c04624a24ed1d5909303d73e30f75f224cae8a0da4e7b4f682 |
|
MD5 | aa1d2c95e2c8a813ae12074a6776bdc9 |
|
BLAKE2b-256 | d584457835c2de5e04a49ae8124c31d0a42cf6c0625dcfc2fc84992f2bb38726 |