No project description provided
Project description
realcugan-ncnn-py
Python Binding for realcugan-ncnn-vulkan with PyBind11
RealCUGAN is a Generative Adversarial Network (GAN) based model for image super-resolution (SR). This wrapper provides an easy-to-use interface for running the pre-trained RealCUGAN 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 realcugan-ncnn-py
For Linux user:
apt install -y libomp5 libvulkan-dev
Then, import the Realcugan class from the package:
from realcugan_ncnn_py import Realcugan
To initialize the model:
realcugan = Realcugan(gpuid: int = 0, tta_mode: bool = False, num_threads: int = 1, noise: int = -1, scale: int = 2, tilesize: int = 0, syncgap: int = 3, model: str = "models-se", **_kwargs)
# model can be "models-se" or "models-pro" or "models-nose"
# or an absolute path to the models' directory
Here, gpuid specifies the GPU device to use (-1 means use CPU), tta_mode enables test-time augmentation, num_threads sets the number of threads for processing, noise specifies the level of noise to apply to the image (-1 to 3), scale is the scaling factor for super-resolution (1 to 4), tilesize specifies the tile size for processing (0 or >= 32), syncgap is the sync gap mode, and model specifies the name 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
realcugan = Realcugan(gpuid=0, scale=2, noise=3)
with Image.open("input.jpg") as image:
image = realcugan.process_pil(image)
image.save("output.jpg", quality=95)
opencv-python
import cv2
realcugan = Realcugan(gpuid=0, scale=2, noise=3)
image = cv2.imdecode(np.fromfile("input.jpg", dtype=np.uint8), cv2.IMREAD_COLOR)
image = realcugan.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)
realcugan = Realcugan(gpuid=0, scale=2, noise=3)
while True:
raw_image = pipe_out.stdout.read(src_width * src_height * 3)
if not raw_image:
break
raw_image = realcugan.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:
nihui/realcugan-ncnn-vulkan - This project was the main inspiration for our work. It provided the core implementation of the Real-CUGAN algorithm using the ncnn and Vulkan libraries.
Real-CUGAN - Real-CUGAN is an AI super resolution model for anime images, trained in a million scale anime dataset, using the same architecture as Waifu2x-CUNet.
media2x/realcugan-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 realcugan_ncnn_py-1.3.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 483043b16b309a8f4ec4050ad0dc8df321b921fe8b1819345213b5bfe0eda96f |
|
MD5 | 466ed41da9e27056b19ec99d07c3f734 |
|
BLAKE2b-256 | dd3750ec2c4fcb63d8067698d0df531433018623a46608429f2d0fa55ede3289 |
Hashes for realcugan_ncnn_py-1.3.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f321e8f1008e0875550cf270c09c4623e4ae83c27dda0e08ded1e12165ee2252 |
|
MD5 | aadca89c045ed1740b8174b4bf1efce6 |
|
BLAKE2b-256 | f1dd344549e2aa0a74dd01d006081aa4e18be15b9284d7ac34bf213ebb8bad1c |
Hashes for realcugan_ncnn_py-1.3.0-cp311-cp311-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76ecffe35c85ab432a74aa52a8bda70893ec5920b235a23cec3be83274348e81 |
|
MD5 | 3411b8888a470e289e4c8d36f9042957 |
|
BLAKE2b-256 | b6a1449d4c691bc78c37165285e9e675569f973aa1f8d7e03661e5dbead07c78 |
Hashes for realcugan_ncnn_py-1.3.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c4b3f70d941d2ab8f33fd1cc073e81792bee5a31bef07de56a78a9d5736c93f |
|
MD5 | dbd8842cf881ef67fcd9b861424ad0e4 |
|
BLAKE2b-256 | 114f85be3341391e07ea0305c9d4ab2d9fdb919d10650aaf123123ece881bca9 |
Hashes for realcugan_ncnn_py-1.3.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b95322ef37ffb8e8e003990f34b384c9cac688072beade951f4022dfd3313c3c |
|
MD5 | ca18fa599bc217444bfe67c2246050e5 |
|
BLAKE2b-256 | a4c9ab6cd514ad16808a79347b75b6c95fa77c10bac9b4ae410ca551700d40b8 |
Hashes for realcugan_ncnn_py-1.3.0-cp310-cp310-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5556ed05f9836f532004606a4acdc2757ca88bca89123a001af5fd9dfd07e411 |
|
MD5 | 8ed19c894a414aef8ba09d208daf2bcc |
|
BLAKE2b-256 | 1fb8ee31c1f790570ebd51a415bea9cb413125708095877e5a20d641a3aa8284 |
Hashes for realcugan_ncnn_py-1.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34f886b48792ec562fa49340a2e3d468e4bfa23c5fae6bf3c4a18393bc9a465f |
|
MD5 | 32e29e4d0b4dc1f7ab0e4ee745b6d9ee |
|
BLAKE2b-256 | 992682d9381c11528ee4826c87a633a299571ad567e6ef52d55ca96be59471d7 |
Hashes for realcugan_ncnn_py-1.3.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe5d9aca80a24cab771417f878f29f6bb1e475e5806c6a000c4f72bb3cd6bd4e |
|
MD5 | 48462ea92ad69a077a2a8fefd853d6a5 |
|
BLAKE2b-256 | 16203b7882290521442190f67584dfd057639e55500171e54e4e68fff383dfae |
Hashes for realcugan_ncnn_py-1.3.0-cp39-cp39-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22e96bbd5a88de7d3ce941923414ba1b3edb1e91d738aa802eb9e48c0b9cd6af |
|
MD5 | 88c13e92a17ed5971795404c930a81ed |
|
BLAKE2b-256 | 6477b3b2f27c90f2b1ee6e2c4a714be447aa0bd0458f94ef05ebde7caed7b02c |
Hashes for realcugan_ncnn_py-1.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5007aebb601dc99626add31a4eb47d42b6cb6c9d6ed9b1f00a9d30a85d2ec477 |
|
MD5 | 03f0d23cf9dac37d7a97bcae8050a1eb |
|
BLAKE2b-256 | aa3b997523326207c4a67ffdf91d37eda6bd04c8373cbc2e875d70e5ffda55fe |
Hashes for realcugan_ncnn_py-1.3.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f006cfabf1c6338f72d9a133d369cb2f63971c36ae44ae3f19262f03ef6258bf |
|
MD5 | 766a0ad24878fbb252efc754f101d09f |
|
BLAKE2b-256 | e18164d284755503ca7e4211047e300b5da13b662d8a6c883658e37e0f2a225e |
Hashes for realcugan_ncnn_py-1.3.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54368880c717871e05967f9ffac582c297d92e98ad158e88c0da798197d63aae |
|
MD5 | 0ad3923189ad9301d2a615e54f23b76d |
|
BLAKE2b-256 | b033c21aa5de001b21bb54c723aada7d9cba7f104d06a25c551b448174eecf12 |
Hashes for realcugan_ncnn_py-1.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 755bf2c82a88f6b698deb4eadaf1f89adf1f94b23a3e9da617de408b888bdfd2 |
|
MD5 | 45f9d07a04672de191f5f387ccfd8866 |
|
BLAKE2b-256 | e4f33b777ea9c8c76453700505aa35239b80cf8ab82697689dcf71b8ec5ef8e0 |
Hashes for realcugan_ncnn_py-1.3.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2e62e9aa200a6373be414503c76b023d0699a58b872f8b0f1883c6e1811a4f4 |
|
MD5 | 13de8d8f1a7bd7dfc056094254956a49 |
|
BLAKE2b-256 | e075ffde684df9b5f11f28d016e1570c7b519109a1cd56c811255db1bc1e333c |
Hashes for realcugan_ncnn_py-1.3.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e90b082fe957bb37c6bac713d334049ebf78bdb3693ac29ceeffbb20525b3631 |
|
MD5 | 07a30fdf0c67b5ddf55e8dd7089de9e9 |
|
BLAKE2b-256 | 49aa51f32c6d5b21b0a411006190d4e6d4b372f62a25018cb24196b6dd7c2828 |
Hashes for realcugan_ncnn_py-1.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c731150cd36ca47509e583ae9d828fd7742c296e830c772c91ddea5d68fc6835 |
|
MD5 | 3a8673f94a94028cb50ed2b01a1aaadb |
|
BLAKE2b-256 | 950d151731f347435ddf6f55ff56256ad68ff57ffb9a0aff8046ea64f4a7177a |
Hashes for realcugan_ncnn_py-1.3.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ce8570c99acbf3af97a4bd61748e75ffdeb4c8147f4d013e9c915100e7cf860 |
|
MD5 | 9c6ef09e447996f61371873ee3abd3db |
|
BLAKE2b-256 | 18df956c27e96d72ceb7803a63a7c2f5de84eebbc7675a228d0259237783376b |
Hashes for realcugan_ncnn_py-1.3.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e018d57a0cbe0bc839d6c07435260251e460298ff91c8937497bceec55406840 |
|
MD5 | 6e3d8d5fefecd6ab1ccd066da719975e |
|
BLAKE2b-256 | 756260d75c71c24509a3433d7a3ef21d30c55733fbbf6f7162ac1ebceb4a964c |