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.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de5b85801e268029130ba6b28c16642afdf2a3129bea4f071767b806c7e9aaf1 |
|
MD5 | bfceee28523607f6e071e61608c5c167 |
|
BLAKE2b-256 | 262403699b2c036ddb5657e052abd8387d3ac94b20dc2cb57317769245aa1b75 |
Hashes for realesrgan_ncnn_py-1.3.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3857624ed2232259fc129306f3caa6654779c0eea7e829065d8394cf7c9813e |
|
MD5 | 28e2035d74dc08093cafd0335ef6742d |
|
BLAKE2b-256 | 330556ed000c9e3b84ce97cf944b550c49b2c6260ac097e339714e3cfbaa3012 |
Hashes for realesrgan_ncnn_py-1.3.0-cp311-cp311-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c36456c8665785ccd244837b85e6cb5fe8e61e7aeb109718c104f9e53e5643ee |
|
MD5 | a9e48be2305d98f604ad6f79f0bdb79a |
|
BLAKE2b-256 | cf68c8139629b63d873bfc119cec900010a6cde4ca884bdd50bc4f6cf6280f50 |
Hashes for realesrgan_ncnn_py-1.3.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92b6557c7f41b1700ebbd45e64fd84d3aae602c8e125f85b3a444d362806e937 |
|
MD5 | ff7513830763985e60029de9165ae548 |
|
BLAKE2b-256 | 3f78a29834ddacf6ca5cc9279ce9af193587608f008dd8cf6a80f6aea23fce76 |
Hashes for realesrgan_ncnn_py-1.3.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df27d25fef2b147b3abede875a4c329c9fdc2a2e7ae0e0ce949a1404ac39983b |
|
MD5 | 1613388758bcf0a43fa2187346c957bb |
|
BLAKE2b-256 | d9aad38e52ff5251d270322eb50fba9592507cab2d6a9c5ca9f5e655dbb4f284 |
Hashes for realesrgan_ncnn_py-1.3.0-cp310-cp310-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d029f27070d1e3330bc140d82273fd976e1cf4ee453e52d624febd4119275c27 |
|
MD5 | f85d80e39772131f42028f907a69beb9 |
|
BLAKE2b-256 | 7ddd2ac24dd2a605ce32af3638ca63f080f0544dbce6f667d6d301a945406592 |
Hashes for realesrgan_ncnn_py-1.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 638526c080e78ffe65638e4816de8d665896db73b7f9226a97b7b611d3cdf9c9 |
|
MD5 | a976c83c5380f8c9fadace949a23f876 |
|
BLAKE2b-256 | 313377bf3b64fb5be7acd4d7f02d62081ce94e9a81c0bd95ebf6f3f2f6e23d44 |
Hashes for realesrgan_ncnn_py-1.3.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a51bd7ff3f319e22b0fc7db74b2276cf12ea0c4f906e35af9e901691433e51b |
|
MD5 | f352e2e505d19a7fbfe1fe86871703ed |
|
BLAKE2b-256 | b9f4604f7cb05dddeb89ec8f78e8fe12eb97e27aee44cd5d9943054fe2a6be68 |
Hashes for realesrgan_ncnn_py-1.3.0-cp39-cp39-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 357f0c6c1472d50182ffc380313d98424d325841face522e6912318bd26a9efe |
|
MD5 | 3abceb96ff2a1705598c906dbdc0fd2f |
|
BLAKE2b-256 | 23693ddef1a515af09d7ecd0f7763ef114474792d7494a87c69a462e9966de2b |
Hashes for realesrgan_ncnn_py-1.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1991bcec147d4cbf061d6771e68f492533c71e437821afa2d0993e3fa5566e3b |
|
MD5 | 4530f0eb09d74368d96841c1bd80e7cf |
|
BLAKE2b-256 | 76c4cc3a16c457e6d76b5bc90940d5df4e5136c4828860f5e2ae3aa130a29c98 |
Hashes for realesrgan_ncnn_py-1.3.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85ba57783020dab46bd2f5af47634d9b46ffddcdc4151fe727352b2ab405f47e |
|
MD5 | 47fefdec75a06fccafc4d0fbf3eead93 |
|
BLAKE2b-256 | 7da863f13fd8709832ee34ae28d88e96f5408d96ab9197a2c80160b15c07c293 |
Hashes for realesrgan_ncnn_py-1.3.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9602ba146d7e6e166fcf93bfdeaf8fef520532fc9bb98ac0308e605a0a8664e |
|
MD5 | 2b5d46256063aca92a90128ef349a26a |
|
BLAKE2b-256 | 333c901d08d3d073a28f9e10fbd07820d49e4c27388fc5bf13c326275579ab4a |
Hashes for realesrgan_ncnn_py-1.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01bd6deee4c612571178fac2ee511e21a13d2f496096fac44af756d734a34a67 |
|
MD5 | 4feeb5218abb9bb9284313aae81fc5f2 |
|
BLAKE2b-256 | 8a8a832602dc17e8128a135bb52d489ee0442e9990a1a0140cbb746b6a9cdb55 |
Hashes for realesrgan_ncnn_py-1.3.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 423add512b72100c6cca5b775004015faeeff33e76e1e69de0ae77c2c45516de |
|
MD5 | d6d3321618145a36b1c7ce7587d9e0cb |
|
BLAKE2b-256 | 3ad89d6ccd611785c0de81fc613c83aa5d399f76dd28b62d7460609a9223918c |
Hashes for realesrgan_ncnn_py-1.3.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e7367c3668cd653a25a33ed55ba1bb3cfa73366eb4ec3a582a70d34ed023c1e |
|
MD5 | c6dfd1d3fb66904c2f0caa36211178cd |
|
BLAKE2b-256 | 6df8027724e1422680c3e2963ca1a36a0ede5c071f159f3ee0b93813e1943b55 |
Hashes for realesrgan_ncnn_py-1.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f704cc93ab7007a819599aa452e0e90ff1a84a5ed2404a5d91f9ac9265e99e9a |
|
MD5 | be604bc6d5039fb8d726ef8d9e44bda1 |
|
BLAKE2b-256 | a9053ed5ccf22905ee986237df8b2a7f7114e512f8d4a890b5f41abd6fbac4b3 |
Hashes for realesrgan_ncnn_py-1.3.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c94ae3b5f510173aaff57dc3b134e7b76d733722e783e66c8cb38438d3c3dc0 |
|
MD5 | e49405e51b56898685b073b36c410ab3 |
|
BLAKE2b-256 | 175851b65f1f6f7cf1a82470741a945681daad1f868aaba30203874566fbf644 |
Hashes for realesrgan_ncnn_py-1.3.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a725cab952285f81bc71ebf0d74a13a181e966a48574fe21769d8d10a9cd75a |
|
MD5 | 676842e95d720b903733aada7d93e73f |
|
BLAKE2b-256 | e0adff501c315e2dbc61f1ce3df855d561c102c085d6773028ec2b8ff35d8c64 |