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)
# 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-2.0.0-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8500f321271cfab07785f8a4ed8538337357d3d1332fd5cd8bfb4fdc0a9ae5a |
|
MD5 | 82476e09d74e5309a767f4958fa88915 |
|
BLAKE2b-256 | 08c4a23692939163be6104100bec46be10555ac0e2c6a58ce0202d8853d8e365 |
Hashes for realesrgan_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 166e9cc5893a4623a3542d22f71c085e663f85e12a4d4bd993533deb7a96f667 |
|
MD5 | 70c7bf822d63d74813749585420ac61d |
|
BLAKE2b-256 | 8b827354759d49777e3201dd6307b798c74d613c482876a7be659a9eb50506ed |
Hashes for realesrgan_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f1aa4eaa840b4f02e57b932c1ce6074722e9dd85c68f9195d266efefbbe93b3 |
|
MD5 | ed2175e067a4eb87429e8f7def6d472a |
|
BLAKE2b-256 | 7531ffe774960fe6469d520dfee3c1dfb0477e2beaa72e2fa5a80f70ebd19cac |
Hashes for realesrgan_ncnn_py-2.0.0-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 412ae180178933875b4fbcae040e0e1cae98be176d553b40f9a3c09419550dff |
|
MD5 | 4c7232f6b9cfed385ce1161e03f386fd |
|
BLAKE2b-256 | 5cf751a7fd21a015256d59bb2928640513870a817d800fe6757464b168c79350 |
Hashes for realesrgan_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b187dcdc3c5ed6f9f842d7fe01dff81bf8f94a72db5f2fd6789757c659c7866d |
|
MD5 | 3745ed778b966bae88caf6bc1b33255d |
|
BLAKE2b-256 | 0101881307e1bbca0af08e91fd578685f2c14db2aae66914ee23e811adec7abe |
Hashes for realesrgan_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d63cb1b5df7183203b5fb095a5c90e7e96e18ca544817fa099831c466ee0a94a |
|
MD5 | 368c627a61c184fef51166e9aa7c9f90 |
|
BLAKE2b-256 | d966a9775725d7c04fd98191374b7ec2a3c5d319a28d989138bdec1c1a15a908 |
Hashes for realesrgan_ncnn_py-2.0.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc9b5b6663dc2f983e2f905dcb45321e033d5af01e21cc508792f38fa2122e2d |
|
MD5 | dbcf4248efe11ab4cc20c6228a327a9b |
|
BLAKE2b-256 | 6e7bbccc40f69ecfff6f909891a746be5708650e5ed8afe7173018a3fee374ab |
Hashes for realesrgan_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 599a6bc7f296a815ebc6505079a402d036f89c6f923c67dc1eef148b6c4b280f |
|
MD5 | 4fcdfec49e83d2753c9ceb6419ba36f2 |
|
BLAKE2b-256 | a73a00d9f0f0639310f49645b241e30404c5a61299a37263f021c319df53867c |
Hashes for realesrgan_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4447e80da84aa039c048465d1e86ed3eff4993a36b56f7e1921d72d25409c69c |
|
MD5 | 3eb97ed555dc0bff195a25a9fbc0939b |
|
BLAKE2b-256 | e0b8260c28d9d173ad358b0e703dca4a78613f5cea4f0c666fe2599b41bdefa3 |
Hashes for realesrgan_ncnn_py-2.0.0-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af7f96d679513bf54e48a6587685c5a58ecd56e252875d8abf8383f43fb3e2de |
|
MD5 | 9eaa034b7dea09e9d2eac6e1fd545d8b |
|
BLAKE2b-256 | 34a6367f3af209b70e946c9b14a8a31546c60386a3d5f85c2449c8fe79bf8866 |
Hashes for realesrgan_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbdbc141d7fe8bd2034df6c0b705b378334db97f1c0c69dd10e70ed759b2c577 |
|
MD5 | ace04e1572bad9f169d10911aa1e6235 |
|
BLAKE2b-256 | a2a831c03b3ab82c94fb309278df55ff172424d8d23e15bd0f4588b976c965a7 |
Hashes for realesrgan_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 434bbbed7c330bfd4b59514c7d2fae13d9a9bcfa6906b7eeadf1e2b13e354ea1 |
|
MD5 | 55d8c446c3d1e070f0bef6de8bc7b779 |
|
BLAKE2b-256 | a4bc794fd2aafeb1030693d45bfb01ef81b498487cb7d08a5046dccd76293429 |
Hashes for realesrgan_ncnn_py-2.0.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efe496bfeda8d2a5e3224147e93fffdddc8b00084647e70aae4ea7054cfea439 |
|
MD5 | 7f9b810401ecb54cdf94f60efc0e4f7a |
|
BLAKE2b-256 | 635b9c3618958b53d72380a23b2cee9f822c0265a2408f9f9999240a13edbe39 |
Hashes for realesrgan_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 260f1d98dbc262212f6fc9a77457b5ef7c47cf0db4550a86c3b20c486117df9c |
|
MD5 | 7a054f8e460360ab42bd029312ffc43b |
|
BLAKE2b-256 | a9cd17deac8af95aae1b03eaad7828aa0f488907a6947493372ddd3dde0102d8 |
Hashes for realesrgan_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 131f083198da6d4b5b4d01597feac759c33c5ffaf30a5be28cbc8ffa1c61e663 |
|
MD5 | bd2974dd31b781c956679f7b0d24d846 |
|
BLAKE2b-256 | 047f08691d3ebfaf39a1c49238a5d150e88cc4975ee1e9f3c72b6d6880504a4c |