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.0.0.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 591364758027a53c13ad45bfbb49ab85eac2cb36a3a6b605c689160be4a3211c |
|
MD5 | a4bfc9c480196443eb1a37c87e98d417 |
|
BLAKE2b-256 | 5eddc5bd15140aaef18a58ae7174d6ac34b3e51c50688a22dc59cba72512fc4f |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9a4394e4b727e936e0d9131155b7c509fbf0eca8ca3ec1e374a412aacbd1604 |
|
MD5 | 9724848292c7e5adf3ca01c8b5876738 |
|
BLAKE2b-256 | de38c703a4839892ac23a357ac3fe98a5a00c2f69c7cea9b4f594da908c5795e |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a176d8e6556c058d63c357169ab5737b566fa13145ef4b1a000af79fcf311f06 |
|
MD5 | 4847a4532a9c7b273372520b8fea094b |
|
BLAKE2b-256 | cf95a5fe9e4c6363b4e3479d0f6a08271be0fed0c8039667b7ad7eabee4b4676 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed3b4d0ec43cf3b310758c8efaf173722127117f3242c918c27d60879c9311c2 |
|
MD5 | 85e5de1c31e543afa0e1dc5393bcb9d7 |
|
BLAKE2b-256 | fa270352a25b9f55907ed9cc26e7a2660108e710de898f046db66c971bdfdd94 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a5b25a53b545fe59d10dcb14a127db571c07c1c26baf74b64cf48584ff1fa18 |
|
MD5 | 3ae51000b28acac747c6227ee8a2640e |
|
BLAKE2b-256 | d69152e6b13ba9cdd8ab0ede88511a5287fa7bfbbb3e11c81c16e1a55db27fde |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1479ae2f2b97d540497f3844acabbb28acef5f8379a8fcbc14a5eeebba233421 |
|
MD5 | b82cc3b84f6dea73e8c71ed0fafe6a5e |
|
BLAKE2b-256 | cbe0de24975399f2d90685633aed579059596471315b13b1db105f7dc1fe4038 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d44ec8c0552c039f82c4a2b714739642a8048155a6f480ec52702c74b8b8defb |
|
MD5 | fe1e20f95594d43ebabe0b79ed14a273 |
|
BLAKE2b-256 | 09e663f8c0b39f2a1577a5c3538c2b61e106967c30954de50f6262aa0d72ddce |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe195a3026e800bc1c3a5216da4734efc4ebee2520f6ccf5aad4a5202418125d |
|
MD5 | f4f368edf70c57e98cfc5a407e3c4970 |
|
BLAKE2b-256 | 17071556ceff6111d32ebb5597a6d08685765eddb74d18294b8ca6ee260cd04b |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0c0b1ccc7a664f9e69d9e063e6d32391be8f0f7adbd8f87205f8ade90ade862 |
|
MD5 | 1730ac021d18997beb5a2fc5d27c3472 |
|
BLAKE2b-256 | 46555e145bac10282d26a6c7fe3f947b6f6d97fa015c80861f8ffa22fd0589d9 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46d0f8cc7ea0d7171d7f44bf9cbe5bc89008f940a7df11ff8e6a585418e0eda5 |
|
MD5 | 0421dcb52d8d11d4c7b00b22eab9afe4 |
|
BLAKE2b-256 | 4205ab2c4ea6aebfe896ae3306934d0fec4d09985bc185aed79b146a52abca7b |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a96dbcb4a19f96a70cc78bfafa29a5c5e3ba5df12a81db481c6f82ea16d5cfa |
|
MD5 | a2ba004edcb81accca35f13ffaa26cf5 |
|
BLAKE2b-256 | 895086185752bd6b0d7a08fcb8047b0d745bc54a0602688f12d236760a18ae09 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 251331866af8d820ac553ad5ccd6c3d46e235f284fe58465845f266905391180 |
|
MD5 | 4bd4ba5f605bca181e4b5379bf96525f |
|
BLAKE2b-256 | 900f9c6f56696eae7e6236920c5988ff790d5b6046f162dfad8248d8066ba859 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 291861469c94f7589ccaa0c0410f25148590014f2db867367acd1eba4ae87d0a |
|
MD5 | ecf2a4847db3b774362768eda483628b |
|
BLAKE2b-256 | b90585de432487c7fc07caf347df756b2c281fb08175ab226d91d6b5002efc36 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f4c09ba8af8db70de372b6ae4404553f642d1edb67b68cae2789beb204a29ba |
|
MD5 | 257ebcdcc7e955765c0663f29a27ab26 |
|
BLAKE2b-256 | eb68053abdc6e8c4ad8e2ceb777ef2049885196956d945045e1fdaea9d833b18 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c67bc99f8acf6e10aa9cd906ba7563c6abb617251c4f8b844af8e09684934d |
|
MD5 | ab39d9da4c162f74706564debd67620b |
|
BLAKE2b-256 | bdb610786390b970b1b7f52d36727d8952b2bf79bf17070cd404825b347af8c5 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ca8fe381608da49467b502e851ab62d95db220b91ae21ccde28ec67dfa2ae4 |
|
MD5 | b4af39ccabc8ad7c5fd3e226207487de |
|
BLAKE2b-256 | 7a680c96a720175d5f092d1044a306a33cc9d832d3b479ba4cccc327047523a3 |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aeb921e94d8cf79b416afffd02a13fad00e37e3952265597d05815da6904033 |
|
MD5 | bda7e30157372ca4530439632dcedf82 |
|
BLAKE2b-256 | 1cc3b72a02c7213de30458f9cd525d7d0d1eaf1d1e23641d32453bb39551294f |
Hashes for realesrgan_ncnn_py-1.0.0.2-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20d922ba494498f6238cf31f258bfda62a8b189940c80b594d558332cc9821c9 |
|
MD5 | 0ffc59619fa89c4d179defe7291e4906 |
|
BLAKE2b-256 | 67bc60dab73e2d647a51b5c0a007f4fdb3447e5ec1d01e389f58bd2c4da75001 |