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
System | CPU (32bit) | CPU (64bit) | GPU (32bit) | GPU (64bit) |
---|---|---|---|---|
Linux (Clang) | — | — | — | |
Linux (GCC) | — | — | — | |
Windows | — | — | — | |
MacOS | — | — | — | |
MacOS (ARM) | — | — | — |
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.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f799c0083d452cbeb6e68a5cb607729632b63829490bcfcac5f785a470e9562c |
|
MD5 | 1e5fb47b5f080a25b166994cdc5f8dc6 |
|
BLAKE2b-256 | bcc48651c452b02ce5457d3435487d4996695335a619a60de9eb40dff09a8206 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d7258d991660ac03d6f726532031e26c66d390c46a7ccac64f7c9a43e033098 |
|
MD5 | 20b3d0f147cb0ec7192d2e9cb323900c |
|
BLAKE2b-256 | 05e4446ef8056a8770935a26590419e4b3ade77aa9bbcfea1a4f38738915e8f4 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bbdaf201f9d19fc9209c77a5b5e2555723f77c300ed6abf0e84bea3121171ee |
|
MD5 | b6a6ba37a6490fb129a05f9d1e2250d6 |
|
BLAKE2b-256 | 69c8f34f08fb4bdd2311c15870b1e676eb85d70f56a92435282cb4618ee1b3a0 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc73a0c12471f0fb386a4c671fde8046b117cd3c707d760e68e3171530dd0200 |
|
MD5 | 5517b1dd1f47c0975a56b1c7ac0b8430 |
|
BLAKE2b-256 | a53587b4b58482dfebcdbae17f0ddccd2c9701142fadb08da63caa5308f3c78c |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 143431ac36d3f2d63d193aff6ee5321441a904b98dfb0977c5e251232e4b9d72 |
|
MD5 | 7ce17e7962734346cacb9016aa48b4de |
|
BLAKE2b-256 | 2f52ea59244e256f37af6b33f3507c8c429cf2771be372bfc4c9b014c76bf73f |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 420776a376391fb02847fef21e31b488eec287058c2a70b28fb9fc2da86a7f87 |
|
MD5 | 4ca67ea8c653e04aac3573f9064cc9f8 |
|
BLAKE2b-256 | 77c12c095ee3b204c8b2d3ff816b65c406d31a6658f79905b76ea833f3d8ff36 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 486e9c934ea44f2a4a537f625e766711192707bc33744f09b6d5f790d524e10f |
|
MD5 | da5c3e58f1cc9386cf1aa09ab6796160 |
|
BLAKE2b-256 | 49625103ea7e85275f00b5b03e5aa7bb0e47f1484880e13fdf0dc431008953dd |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 062d389947c559908640bbf9ddf0c979864f648d20f4ae69261ff8758b9cb7c3 |
|
MD5 | 7112d55769abeac27bfb2a95286a755c |
|
BLAKE2b-256 | a45bdb97209355229afb6270acaa12ccb4493eba31654c107b8965ce9debf616 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d4b452190447f08350edf6ca3505a2d561bf1cb8c3dbd60b4cf13174643e1af |
|
MD5 | 30a50cc3ddba96055a930d7a78f00937 |
|
BLAKE2b-256 | 25dc6cd4a37e54b95b1096f23acae45d3f2cd10df30ab6b4ca111aef8d9d298b |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b6ad4ac380b696c285b98e7ff9538afb267d899ab4a69d0047dc09b6b94a8d7 |
|
MD5 | 820b58a0f5ade6feaec5ddf8c0a0611c |
|
BLAKE2b-256 | 7fea2a05a51712b7ddb416bdfbbff15e8db69eac7714fd8e73ad7f937d966c03 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d417ddfd63a523a4de6e2f82fea734be38255870a6de160472184f8c6e5e5e0d |
|
MD5 | 7c4ba16a08cefe384819ff1290459bf9 |
|
BLAKE2b-256 | 1f9a4fa6b3bad87e0c53cc1bf428d13b280af67b573ce427baa2677421625ec8 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35bf58f0b4a5eeb9668fbfb4d65e202ba354714fe2cbc2fa14dad62c7b0981ac |
|
MD5 | 8c4dba1a5eada386dab05ce89d101f4d |
|
BLAKE2b-256 | 135c7e0a85fc042ede46e083fc60a625c54838eb973acaf787a122b2c952a0d8 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59e9f6757ebba166261772a03e8e8e07c499937a3130d446e596b221e63fbd12 |
|
MD5 | 68868d2b185056e453ffe8d900e00681 |
|
BLAKE2b-256 | 6af9333f069e0ef481693fb87363d1d5ce64129a9204d42971d71ab7a81bcdda |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2368b92fcc7e9f68f4e9e17b6dcfb00624150f22ab6b53e5844ce01f5d3ac79 |
|
MD5 | 3642e74975e7d9fe958e0067a61aa8e6 |
|
BLAKE2b-256 | bb99bef1f051c03a4b716b92a4f9521e388968dbe2e4823ccba1e155dbbfccc0 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15d92f61997cc06f0c0c450160c7cd3955c0c9a387c4d6998cd3bec44a2675f7 |
|
MD5 | d03a22746d19a095e197e62cfa95143f |
|
BLAKE2b-256 | 477da30a1e6a7cbb2bd2d132d703a608b3f2ed96565760df2a3aeb7385bad1e0 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2138807fbd056da34b3635562a3ebc4d51fd0a206513c26f8870424449d1ea9d |
|
MD5 | 5245956b45a4b386782c75500ab1f009 |
|
BLAKE2b-256 | c0febea04f6ef95bde0547cb05cc97116ef9b7bb711b3877bc88beed3ce5434f |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d78f25b82287aaba9fab7acc61b578dfb4d5879f047b485c0671452cc8951552 |
|
MD5 | 240b73e78a2ccaf4f3265e6d01f5ee39 |
|
BLAKE2b-256 | 80268360a260dcc25e8707bc70b7c9e8fd8018620677d30e89af1b4e997aeb09 |
Hashes for realesrgan_ncnn_py-1.0.0.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50a66f4d2426579510d3e260db6aec97078ff7a33a6ae6b194fb6f3c30d3dc8a |
|
MD5 | d4ed50755c3e0ac4aa02275b0b4e15df |
|
BLAKE2b-256 | 5918c668c0e542ac33ceead5c26d5e0c6327a6fd7dda370b025b99596bdbc976 |