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
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")
# 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-2.0.0-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6567dcb1e00994d8ac7dec4e88abe0d0baf045c5e6093c70ed942eb585607ddc |
|
MD5 | 480d3bb8bf39b38d4e8b1cc09f5b563f |
|
BLAKE2b-256 | 8bf19d111be58d161ef898561dd966c694b125286b77c07761d20f5c8a60553d |
Hashes for realcugan_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f576b86ba4311d245257ffc37997d6d0ece68dbfafbe166011a179e86b333ad2 |
|
MD5 | 2b1d6c017879a5ad99cfacf0032a2e45 |
|
BLAKE2b-256 | c4be880021f75ecd08fe5d263cd6cf42282d183e38907894b17bb767170170e0 |
Hashes for realcugan_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4426769a7079f6cb2276eeddb0e18a0f77a3d0c3e02426b75fbf2ad15e4703a |
|
MD5 | 23ee2ed39fdfb84678cd8df43747ca34 |
|
BLAKE2b-256 | 4a7861f716a4c244950b10fa0f191438d82529dc2284c7beb4b969f20dcb8114 |
Hashes for realcugan_ncnn_py-2.0.0-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 538cb74c8d2fcdc014f234aab693afcf0aa2eab3efd85dfb71be273f1e2654d6 |
|
MD5 | 98fb84590941c348b09873c04a643724 |
|
BLAKE2b-256 | 1a605309933d6e6d30ad9d065081e7652b7b58842bf8d91a894e7534d60d5e72 |
Hashes for realcugan_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 223525ee750d5cf7679213a5891b16dbf8ffe2f84e8a28b6e5e7b5ddddace60e |
|
MD5 | cfe02fa11c930d6d51890ff375d480e5 |
|
BLAKE2b-256 | 4866fa0ed0c0ea1f5f8f492b1df5ae342ea959fbc505a08cfc43db1c3e8b0253 |
Hashes for realcugan_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 255d612006d06579ce67b4943d207650acd66e9b677abb8b42749f91179a0448 |
|
MD5 | 8ce8bfd925341819e5eb6c4e2b20587f |
|
BLAKE2b-256 | 9b911223b0eeebd1513c4738129e860625da8fb5be6e1d813a930864ffa3718d |
Hashes for realcugan_ncnn_py-2.0.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6af5d90b340617148d15afd004ec31fa32247e93d7132e9a6decf656e0ec355 |
|
MD5 | 2c517a53dcbc930db0d437a7ee622a60 |
|
BLAKE2b-256 | 24b799df00b707df08e733ab3ffbc0af841ed90d24b0be93a441baea461805e2 |
Hashes for realcugan_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66891b44a8a09936276d5f629a59f14d7f136289989549b66dfabbb5c8c214c8 |
|
MD5 | fd08c3dbe3074fc8048be7e1d8d4632b |
|
BLAKE2b-256 | 396bac1dd516fed8f107aa1a333423e2f5405cc1cf7746966b484edf3460580b |
Hashes for realcugan_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ed7ee33daa114fb649378097be3a3b246e563a96a2a66569f24fbbe096ac55e |
|
MD5 | c93c9b89fb5e0041c2c2b1ccd7d68f41 |
|
BLAKE2b-256 | e9396355d66c8ec35df5d4abf7899aa4594b6c030a5cc5a0fa3519fd469f4043 |
Hashes for realcugan_ncnn_py-2.0.0-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bb1f8da181f0fceacb8287b2e38c092c740bb9d6a6909248b9c87c8b69c93c9 |
|
MD5 | f5cd4c1efe761fa126b9f4ef7739d590 |
|
BLAKE2b-256 | f153a1fd0f9769cd315b1fa1dd0fd5fe9207e429fcf506ec026006a0f77b357f |
Hashes for realcugan_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c603582092b137951cbe84dc7e749d53c81326fbdce879fdf9739d2c4cf014fa |
|
MD5 | bbf808c5488928df64940b9db5a701ce |
|
BLAKE2b-256 | 98f7e10d4e375b34aa20a730875517ab687a33a6d5ec64934d1a54ade16a5c53 |
Hashes for realcugan_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c05dd7f1f7f5cb9fbd66efc5ab9606f9a3fef352dd9eaa37b9a95030af4cba2f |
|
MD5 | 6c46e9129d127cfc09b5bafb33428c15 |
|
BLAKE2b-256 | 63add0100c14bd673e577c9587ce78ca3238ca40ce9ecdf2124a433e5a373859 |
Hashes for realcugan_ncnn_py-2.0.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65d56be23ad7db26ea9cbbbd73990eaa44a43758a657b620be490177c4874eeb |
|
MD5 | 69f09450453530f9978032ae9ebf3c84 |
|
BLAKE2b-256 | 531a4ee6dde1279eb86542935881d26c6e0375d4e4455867d453c34718ebbf1b |
Hashes for realcugan_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac02a50e8cd2332d7f9f3867fc748af03af3d78a47500e9c8b68588c5d840775 |
|
MD5 | 00a5b5c6cc6e7834107c5f8e1e79886d |
|
BLAKE2b-256 | 8c3fafc74ce3561bb0e1a6fb902dce1a4d892df5368dca7b42d74d0e6546e041 |
Hashes for realcugan_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c38688c1dc15f28e2eebb6375861fdebb4fd913958d80ccbf2eb415d3e578f19 |
|
MD5 | a90379a86d214ce385f6e19bacb33368 |
|
BLAKE2b-256 | 102c78f5ca06e446458688e52a15493e992d7ef8f22c79cc49c7a3d98c15d3e8 |