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.3.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 931c4fbd0091801c0657f283ec430f8b71c8315b6b0dad36231eb2ccea999554 |
|
MD5 | a6c5a1b762ceb7ab13b4a1e54d0dc05c |
|
BLAKE2b-256 | 54c75421b4be2de6a77951e76360b5f47e06180adc6a0d7beef8e0df156e9daa |
Hashes for realesrgan_ncnn_py-1.3.1-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34e078d4545552d3efb3bfc1ab6f1906c57a544ea6827b15451f5bb710839e12 |
|
MD5 | 5121893bbacaa95519fc066b8f7bb0bb |
|
BLAKE2b-256 | 25081a9cea9db670a057ad0eb3f4c7452a7c16447c408c5745f188cb3f9e79d5 |
Hashes for realesrgan_ncnn_py-1.3.1-cp311-cp311-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 838abb5dc7b58c81fdc26f7b6e19c51f4fa7b994bf7e0d13217835662bba5374 |
|
MD5 | fef387c4d8727dfa1ea0ca34897e00f5 |
|
BLAKE2b-256 | fbf896b2cd9658c99fc9533f64d80366b78d6db33d1d34b0f4e5db34c2812194 |
Hashes for realesrgan_ncnn_py-1.3.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40b0f221a11a247aba78fe60ed3143b80baa3bc8735f51bdd8e0ec428a492453 |
|
MD5 | fdee9dadfd414ad5cc688a851e4d4133 |
|
BLAKE2b-256 | 582984c2c493b08faed8d0b0bdee479a24139b1cb56b8cec1c94957a9b7504f0 |
Hashes for realesrgan_ncnn_py-1.3.1-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c165269bf44c1dca2947810dd83756451389451ee5c0f8e277c250c598faa9cf |
|
MD5 | dacd24fd14e0b8ccf65f276fb3085b2a |
|
BLAKE2b-256 | 9be163ec77b10767c5111464edf4bb3649e47660fab3c56c926baf826d8fc18a |
Hashes for realesrgan_ncnn_py-1.3.1-cp310-cp310-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c999091d7d7a89b8a4f8760a18d47a22cdd2d5c15013c39205639df1d701d815 |
|
MD5 | a762380e67cfa04d8fb67d8002210734 |
|
BLAKE2b-256 | 0c63db3b174de50c61fd670634a24859f6c2d186f55b5acd611eba31e86a8f14 |
Hashes for realesrgan_ncnn_py-1.3.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54d5a7b0a06ed9639bea77f36deecada55b70455db3027a448233ec2fab4e9a6 |
|
MD5 | 040f82e57170030f7f3d83cdc9dca772 |
|
BLAKE2b-256 | d544037b8d53e636c659cac1ac01bedd549a4a2dada871e484c44d3d671f7a20 |
Hashes for realesrgan_ncnn_py-1.3.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f4c4b25449b13fc7f8e09d68fc60dda0646e40b28c26464f4b0039d930aa2b5 |
|
MD5 | 68b9957647d36409c4d598e1c381cb05 |
|
BLAKE2b-256 | 00633a276389e0d0c7879e198618ce7a74eed4bc875f44e4086838f037d3869c |
Hashes for realesrgan_ncnn_py-1.3.1-cp39-cp39-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3dd9d9d601152b0451445ce372ac2a6f8829e5e9fad1c47f5858921f2237772 |
|
MD5 | 5c931139f07d16c34d3b91255f4d42c1 |
|
BLAKE2b-256 | ef991f2451a9bba3c2a9d6ddc51d598d54769b0c6789b0991ca58fd9f0f3f5c5 |
Hashes for realesrgan_ncnn_py-1.3.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 753fb0b995f4503559140967a51a773a27fdaed48534faee5a27ed057b371111 |
|
MD5 | 23da694488baf34ea0ef80f7f7dc035c |
|
BLAKE2b-256 | d47d429b17a0123a2886db157c511710e4eebecca480f4311541b5b691f45744 |
Hashes for realesrgan_ncnn_py-1.3.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18cc2d84552bf6071b3ec3430a099967ef4a7afb25dc27973586171bf52190ed |
|
MD5 | 8bbcb974501cef8760c875fc4d4e6a65 |
|
BLAKE2b-256 | eb2c45b80ebb3fc65163f79f87dbcd33dcd3d99963add98bf82d2fd002ec89e3 |
Hashes for realesrgan_ncnn_py-1.3.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56237771d737b500b085dad5d35d85be0a4ace92088ef5b150e30e020bc9c721 |
|
MD5 | fcc251476d0deb77b05f374c3ca68524 |
|
BLAKE2b-256 | 03232d58aa23f31bb34602fe1528569014e8d6a2fb72e7c3a8ff4452dc7333e4 |
Hashes for realesrgan_ncnn_py-1.3.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4acfb4b21062227c19181b002aadfe7368f5392216bfe2a603a33b16a4da5187 |
|
MD5 | f02530d3d112753cfcbc5352f5c9d702 |
|
BLAKE2b-256 | 3ea4972375d93988fbab49b839ce203b56e428918b5db89dbabaaedf11c1df2b |
Hashes for realesrgan_ncnn_py-1.3.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbc49fb2d17c5b880e1822599bb2b316b4d9bea1e2e96d6a88c08b93800a808b |
|
MD5 | 5d0bffcb550ff6de5d7b20ddaa909a41 |
|
BLAKE2b-256 | f05424d4d672ef4836cf5c182794292bd68eaaf266e2aa82ee49debc571c20e6 |
Hashes for realesrgan_ncnn_py-1.3.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b19bf3483d1c048f337fc0ccabf67318815d33eaa8ead884a161c59d98ff5f77 |
|
MD5 | 912a7ba6acffacd6e8a452f4996a4dcd |
|
BLAKE2b-256 | 2e0f2c63bd6859ffbc413a15042483ed3feaa1d98cab587b067685456b6ef6db |
Hashes for realesrgan_ncnn_py-1.3.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1d1bcd7ace7198b050e57f09bbebce69c6ff6817adaa36bf1c070fc3852976d |
|
MD5 | 284d6e8a34e536de8d4f43f3dd52eaa7 |
|
BLAKE2b-256 | 5b1e6c6e4c5828e5b11e8e8cfd8cf8e0eba30caab26cbb1c9af6233aff9bd8c8 |
Hashes for realesrgan_ncnn_py-1.3.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 798980cde946c5d7ae3d6c7745e2b12419b157e35513d14098417fdd37923393 |
|
MD5 | d8eb8442daac2981d821cedc5b64872f |
|
BLAKE2b-256 | 09fb7307c4e282fa01fcfabe68153eddfa22b4b6e06f79cd48f6a53876e0c7aa |
Hashes for realesrgan_ncnn_py-1.3.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c6c39c197f330595d2a0a39ab62ed74efae3b6daa42a168fef366eacff0f957 |
|
MD5 | ae7157490e2beafafe9af553e3b711f8 |
|
BLAKE2b-256 | 12c1b411e6e42ab49020c4dda027476f8266044e6b6ac334c04e8517cb7c4d58 |