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.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e12b0eac1214358f3265d7b36d4e83130eb6375d18f59ce0a845d12eb6d69214 |
|
MD5 | fafe385200c0868cb95c64475cbf1604 |
|
BLAKE2b-256 | 208204c9060eae6a6223087927b4b2f2d936565e12360ff8c37ee9e0b9963da9 |
Hashes for realcugan_ncnn_py-1.3.1-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 618fdbe70e977f7c2c2c547bc217c0aa705f7e990feaf1ee49c05ee07fb05702 |
|
MD5 | 5372058341b32baf4435d5f0f70b6786 |
|
BLAKE2b-256 | d99a0bcad60d479ac3e1001cd336b0a309558b12503abb9f5107634eed6c47b6 |
Hashes for realcugan_ncnn_py-1.3.1-cp311-cp311-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b4d474da1a2ea09f1cf8629db090a730635996cbe653f505338ab3909bacffe |
|
MD5 | c7c09bb4da7859b77fd6e358f9742eeb |
|
BLAKE2b-256 | c6325e904fef89f1ba663bce47638c6f8ea793c815ee5f72bacfe8efae417c2d |
Hashes for realcugan_ncnn_py-1.3.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa6d5289049b994b7465fbe6a4ab95ced5762b90836bfe4bdc2f230e37acd6e2 |
|
MD5 | ab1b9b784ab8c407ca35fade58aeb187 |
|
BLAKE2b-256 | def2004f7bb993fbf2032ead3dd6fffa52b38acb5e82b83cd2c0632fcc1e08d9 |
Hashes for realcugan_ncnn_py-1.3.1-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19f63d4e148a22dad57db149574482709043e5b5abd1734c52db414a9dadecfa |
|
MD5 | b50c21e348df9874cad756368ce026ba |
|
BLAKE2b-256 | 670e7a870ac75e00f7a29685380dd099002e80a750624d30443d13325deb7333 |
Hashes for realcugan_ncnn_py-1.3.1-cp310-cp310-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb8217fbd9746dc802679939e22b9b5b669fa202c8b060fdb1a3b194f9a38b3 |
|
MD5 | 147750ca0f214cf8a170cac3b4d1aa84 |
|
BLAKE2b-256 | 41ef3d4a477678d3a3334e086dce65832ac2423328cdce06e146139ca8d22445 |
Hashes for realcugan_ncnn_py-1.3.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b3e3599bea37f5c71dd7a3441d2975db7e86436202d85451deb551c8698184a |
|
MD5 | 666356e2ab097fd8ebdbe3dc02659046 |
|
BLAKE2b-256 | 66e986f9d313947f78488108b00173f6729c78ebce8fff97d27efa90936db9d2 |
Hashes for realcugan_ncnn_py-1.3.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c5cd619bfaf0be7c3b8145c325693669dcfcf5bcd6e0250fecc6856efef1904 |
|
MD5 | 3c4ca07306ad4433cf4d8e62f54649d1 |
|
BLAKE2b-256 | 505044aaabe10162cd5d0f86380c138eb2b105c5347a5357194710c806f73d1e |
Hashes for realcugan_ncnn_py-1.3.1-cp39-cp39-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71b33d1087476055a8a2e138537897ee96a15d0ae5365599d2a52b8b55849b56 |
|
MD5 | 935470bfc633c578c2a8336e5a30a88e |
|
BLAKE2b-256 | ac12d7a1b53b5ce5e6032d2ff1df73c359bec3c12055dd05f23ee44e939a6b6b |
Hashes for realcugan_ncnn_py-1.3.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc9f79c00b7a6533058dd33f17a179592c4d419e965e77578e9b7460f5835473 |
|
MD5 | fa9c4105d14ab1133d7113131603cc9e |
|
BLAKE2b-256 | 3629b0a933add1a45a803578743f1a838b2ed5886bd8ceecec61337ba36f5f27 |
Hashes for realcugan_ncnn_py-1.3.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b74dc91a6efa1bc141d6cabd83f5e434bb6217356a03b15f71c18b0852b693 |
|
MD5 | fa030c4af4dc10b3f8effa67260d56a6 |
|
BLAKE2b-256 | fa59f10ca4924dc0a500fe4bf4d1f9a0625a1381c629f86118b00ff4280ed06e |
Hashes for realcugan_ncnn_py-1.3.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d92203eb23ef16128d24d197c0b7cf9c9ef9741adb190f3555a963398a51f3b0 |
|
MD5 | 3caaefc2b842c85a06e08b049f42683f |
|
BLAKE2b-256 | cd01af7edd8445e697ddcf03a6428cbd7ffa7b9f5ff3d37abc3dbdf60b20ec1b |
Hashes for realcugan_ncnn_py-1.3.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8ae2d248847c8bccaf0d2ddc2a921c5acabee06b8847f35da457c314587b6ba |
|
MD5 | cb7d1ebb95823fa3e390c2c733e91e09 |
|
BLAKE2b-256 | 8e3d1c96add6f54120b040c492fa5fa8ec125b520a947bfe2fbe7477152a476e |
Hashes for realcugan_ncnn_py-1.3.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4752fb3a9d370f514e7f3fd8dd4ba261fa975027d52f5b9e3723a1c76090e07d |
|
MD5 | f782cb6229ae018c229123de39d2d3fb |
|
BLAKE2b-256 | 96d758e1b06715b91ecfcfff250fdac1ed254778009a33ab027ee289c4cc8b2c |
Hashes for realcugan_ncnn_py-1.3.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b3472a51562724f5d3fe641aa8151d3cab65b793442f6d89ef6d61c27f764d9 |
|
MD5 | 6984ec1ab65e765a0ce7e330da0ee723 |
|
BLAKE2b-256 | 153d0290b9dd01b953a699c6ad978ed67c1f2e7dfd3b50b764543a4f820430bd |
Hashes for realcugan_ncnn_py-1.3.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dab8ed60c9ed432aad5e68b5aac91d255c2e833811ee6a11a1bed27b71c82da |
|
MD5 | 5df90c9b0ada2f04465a6fa3f39370db |
|
BLAKE2b-256 | 38ded9c46b653ea2b611a5eae426184d9c4ff33837c3f2aabcf8d2ddbd014aef |
Hashes for realcugan_ncnn_py-1.3.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4c718858a6b764403717b920e9bfd6203a6af0e0c3090707c2936e7a96df6b5 |
|
MD5 | c8d97e9b2e4ac00e680882c3f5b93a8d |
|
BLAKE2b-256 | 3b53d1e4e0c02e92863b47b03f9425514d4a8af4cc74b9110f8a5ddb106d932d |
Hashes for realcugan_ncnn_py-1.3.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18677255489b8bcdb43940bc8f90486291a28f6296b51567404a54e35e453987 |
|
MD5 | 428fcf3d5b3cc12e72b476f595e97b87 |
|
BLAKE2b-256 | 9d3b726ca36da68e071377c7da65b12e4eabd98a3a53da5dd602485d4e9f5a0b |