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. This wrapper provides an easy-to-use interface for running the pre-trained Real-ESRGAN model.
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.1.0.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85ebb9d2230d0a507b5888e96769fa818254c16347a2d4dc9b5473e17e9bf800 |
|
MD5 | cb3c17c1844524c9393da8af8e02915f |
|
BLAKE2b-256 | 76d89048b72a1a12ab8d8ff500fbdc8fcb95b3764adaefa29bc3a8f33fa5bc90 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25f90606d77766bbc07004ed7164423ff26698e2f5645eb034106c0ff47d8e4c |
|
MD5 | 3bc85a082304e4301e5a96dcccd16ad3 |
|
BLAKE2b-256 | 1a10e11bca9995307ad16fa3cc5e0a61dbf77952a7e9b3b2174c202e398c5f48 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29475e9b3f099966cafc401b932b6e12211984ff41b8c5daf75afd61fbe2af96 |
|
MD5 | f6c0c3a7f76a4b79ed53edd83383512c |
|
BLAKE2b-256 | ec910ecb1f33004c16954319ca4aaa494b50c7abf1a4cbcd60dc3d08631e579f |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31db2977019434c02923aaafc8cbe9a77dd1d46290426af280d4b002fbb9c159 |
|
MD5 | 38158f75d3d43948c70e85ca1922618b |
|
BLAKE2b-256 | 316575cf5505e42abac4e03131adc1a634d8b1bd809a7ced124f147ef8228fa0 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7bb636fd912d6a1d9b74d9c03fad7704cd8c8335a8bcc08fd05b9fd995e5c4b |
|
MD5 | d41bd95c2ea1a5fd2b4ccce5cbf42c0a |
|
BLAKE2b-256 | 4b82790f51cfcb8eafd75298aecee216c98afb3e9c63fc4b60c42d438c46e643 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 009deadc88a71cde665ba49eda3b7496d911bb3d77a8a7fffc1994fdeb18df34 |
|
MD5 | cbb0a745c48ff1aac808c831ae11446b |
|
BLAKE2b-256 | 7c76ab43e7b163e248d00d4b2d8bbc665cfe6238c00f73761fdb080ccf5a2d3a |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7c597600f14993a034803a6feae4efadd35877a655c77914e52f62aba76ff17 |
|
MD5 | 286c2270f17115e28cedd69e05279018 |
|
BLAKE2b-256 | a11a0052810be27dc30c9aa3b27bf515bba41fd134c36c9307608d9212eb052c |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c02974787a00d9c527452bced5e857b52fafcc28fe867877f7e1339ef174ee |
|
MD5 | aa5b76068fdc92d802be8c29d37b14a6 |
|
BLAKE2b-256 | 3f77fdf2b3d6676d287e5b420171255b696a247b2527a0a0b2d384e6f85ae31a |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21415542e5dc9f1111883b45554774c5d1f640638837eaab6e1832d5e768935e |
|
MD5 | 1a7778a0d07e8abd39de990555322141 |
|
BLAKE2b-256 | 2c78f953067deff0160b18198076f9299e56a08b4712d9e83601a00eb19216a7 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91af9974af722575d82cfe6a5e7e39200b181845a9a67bbdc6dd7567d14f2a0f |
|
MD5 | 105d8d6623b2889a38d139282d4d1db0 |
|
BLAKE2b-256 | 408795f5b315e3ba91b12249cc106573d11b09714de0d7f6335b7f3d062df230 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b18dccb22aee42ab2bd22b355c4fe3988fa0d8aba71432177e340a427a3e78a7 |
|
MD5 | ecb327da3cbf4fa26ad286599da6fbda |
|
BLAKE2b-256 | bee33e3bfda2a0c135f41c2db256e347b6c56331f3fb9eb6ffcb95c5a1a3f1c8 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1928f2c1ea970f8897e3c68c3f4368fbdc31316cc835f3bcefa02d6304ba768 |
|
MD5 | b56e3d5edaac8446c0aa6360421e0e66 |
|
BLAKE2b-256 | 6c25e991d56baa80122bfdc7cab4cc378139acfa4ce0e47fa7c7ca01ff9db87f |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e913a04bb2b616acab9a85a0c2761d9f727d71ef47bf82c0c26274bbee5a5bf |
|
MD5 | 1f02f16030c29251e581c961fce7e86a |
|
BLAKE2b-256 | 046861af938370e9a3cc13bd4aace53fff82f10d3eac71c4ce5b0b66bc45cdfb |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10d24992744dac7c87f07d22d1c14398d2916db883a20c6cd54682ca98ed9323 |
|
MD5 | 6b743641ceadd3d2904deb66a803661e |
|
BLAKE2b-256 | 922a3c8cf17631fec2e1d0a6889f1f5cdbc6c3c9a572e3ee2f27ab24d5cf6b26 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 509278a5dc442d685d3c60b69df560dbbc7da780c46b387f1c15e5aba07af5cb |
|
MD5 | 8ac725b7763c8af580a8d2b32055b42c |
|
BLAKE2b-256 | 75713599d061e263884bd91a9e3f9c097931e947925fc33923a5aad05e36f04a |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43d147008639bb36450e62673a4ba6b79780d7ddc5feccb99ae67af7064c26c3 |
|
MD5 | 4c7f2e5b84a4f6eae9b4f7459a468c1d |
|
BLAKE2b-256 | 663129ea3554c46c3a6406d7ba13f4f89c33c916f24847ea93c5cb577cbe2187 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03e327995d0d110a7dbf787babc0a29c43b7199bf3f404fb4115ddde21854e20 |
|
MD5 | 370c2e08e7b80f6f1f4f77e9cd8e1ca1 |
|
BLAKE2b-256 | 25249cfc6acf0cc23a1dab102488c5ef5086cb586db2f24ad5606d94ddfe6308 |
Hashes for realesrgan_ncnn_py-1.1.0.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 696176be648e380d6f8822b0ccaf2ab98fed7433cd90964c95d5e6f50b3700d4 |
|
MD5 | e9e2b57c4f5889c2a66ae6c47c7588f9 |
|
BLAKE2b-256 | a13fdcc1ce3e443475667f62669e40b2080fc950bf5eb4ba6e837ffdca8622b6 |