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 a 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.0.0.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99faf38b2e97e6d6d219982602864c6218fc64ec9a7895577e85e25fb7abaddd |
|
MD5 | 447b3dc1470e531a8a33943acc1d7ccd |
|
BLAKE2b-256 | f1bd268838bd50cea98ec6ac056ef2aacde7f8d03f757da4d819754098c50330 |
Hashes for realcugan_ncnn_py-1.0.0.2-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66103f311faf380b9772a964c99d3d3b16f4c537f90e7ce735e5332a175a39e8 |
|
MD5 | 543df3195b7a728442c6a0f8bf8cf32b |
|
BLAKE2b-256 | 2b1e98ba72a4ba3b2192606f13ab26b3be68ffaa76f809c99c35ee26e929c41e |
Hashes for realcugan_ncnn_py-1.0.0.2-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99cfa002410e938edc51fe9fd06db30308b74f2cfdd88e1355f961a305cf5d36 |
|
MD5 | 0b68083dab5ee99b13691682a902f32d |
|
BLAKE2b-256 | 43fe3d49ff07ee4de64610e2b3ce75b4e25ddceee87d641a87fb9e89bb6ccf1b |
Hashes for realcugan_ncnn_py-1.0.0.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d83825006f2184ae7bd777e775fd5e2982dc5e86712821b23d6f2a9bc60d5d7 |
|
MD5 | 49b4a6aa6898854daa135601a25755ee |
|
BLAKE2b-256 | c4d780b48e5bdbdc035789024855cf6143fccbf579638b2ea84f038b42ca4c7e |
Hashes for realcugan_ncnn_py-1.0.0.2-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de5b436060a4da2e6bbbb0fe6b677ac1676e03897060e36e2a93443dba526d60 |
|
MD5 | 1c68c1d34ae9f7a49c2851dbbddd4e12 |
|
BLAKE2b-256 | 7cc4cab5df91c7bcf87ba84f7058f575b0cf93d2edc9cb61aa1e1f99c3f6fd6b |
Hashes for realcugan_ncnn_py-1.0.0.2-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc0c29efd369bf6bcb3ee473eb9c3fbcd0931402da0ea6314c7b983f82d8ac09 |
|
MD5 | 53940d43417b9694b184c93ddff55f4a |
|
BLAKE2b-256 | f6f9c6884717e0b84989a5739a77c52923cea81d0c31948e2e363ee2ad1539ac |
Hashes for realcugan_ncnn_py-1.0.0.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2a2138b098ed5e76626259c94e90c2bb13d3dee85a646e347460bee09ffbfd0 |
|
MD5 | 3e907650b67e09aed85bd7cbcc2f3ba8 |
|
BLAKE2b-256 | eb229cce5989573f92d15dfb48d23b2cc9966c622ef5797d462d8aafbb522c9d |
Hashes for realcugan_ncnn_py-1.0.0.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b33f5fb46b64d4ffc6ea57be787ce526fa67943d434ac93f5edb5a1df0e18e7e |
|
MD5 | 450c176f50c1c6aff6cfc6f94927ee21 |
|
BLAKE2b-256 | 197097e03278f6dba1488561ea7ad7064c6faf7d58e78d40ad47dc4988d83b7d |
Hashes for realcugan_ncnn_py-1.0.0.2-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dfe9260bb6f111747f5bbb98900155034d5b957238eeaab8b6f4c4cdff2d52f |
|
MD5 | 72efda29bbe116e27bbbaf4ba940bca1 |
|
BLAKE2b-256 | f56c0121113660ce00f2b59ee6dfba680b8d11aa137a243eeb3798577802c370 |
Hashes for realcugan_ncnn_py-1.0.0.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8eeaafd9000d6fd667bb5acb29008ca650e47ee2083c91d22f9d8a17127efac |
|
MD5 | b146053ea47bc05d93b739615a55ce35 |
|
BLAKE2b-256 | d7a18b6a9aaf2b45b48653a29254e02488f072a5f82b17976fec5b14b924a7c2 |
Hashes for realcugan_ncnn_py-1.0.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6117d01d97d34256d9d172e47d8696eaf576a9ed392fde737c5318f545875450 |
|
MD5 | 6317a7f90d451346c9072d0acfa0df1a |
|
BLAKE2b-256 | a423a5130832eaa5b2648edfa7bc799a9f0bf370c8dd903213d6b1664c2fe98e |
Hashes for realcugan_ncnn_py-1.0.0.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 041d7737e6eeb27fa68b3946b0145c9f27180828450fb348a01837c1247c6630 |
|
MD5 | d1ec458aa5c379b3fb92048c0454800e |
|
BLAKE2b-256 | e0a0b897f324bcd1ea7d613f24b8997fc8490928bc60dcb1269261f44bf328d2 |
Hashes for realcugan_ncnn_py-1.0.0.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e219318f83bf28aedf1a8a09dcc177edff61e1769122d033a8c0444995fe1dfd |
|
MD5 | 0c09a013a7defb5b2021e7dd3a09f38f |
|
BLAKE2b-256 | 46ed0104c0a97261beeb1eeb57853236304e74fab8d629becda62ffdcec26a20 |
Hashes for realcugan_ncnn_py-1.0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fb648c5537bbb1cf13dddc79ef4527f49980af7e1be3365460dae5de0461530 |
|
MD5 | 713bab37b2d3605a2ce8cfb9fcac80b2 |
|
BLAKE2b-256 | 2b3cf045d0927f0728ed90537c5428a3ab9a57760d962d8f0da5a8a4c6f5c64a |
Hashes for realcugan_ncnn_py-1.0.0.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6e478c70bc1710a9cbf654312f22f7a80c838bbaa93c8b2599afb8e5eeab137 |
|
MD5 | 688c43d2b03001cc919740c9b4f3f98f |
|
BLAKE2b-256 | d757a3c0e62952007e973494aca7769f2c045f9a5e1312055ab73099d856edec |
Hashes for realcugan_ncnn_py-1.0.0.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b07a1246ba7517402d3225a466e030d6a2ef3f35aa6d6a8034d0ef318008f88 |
|
MD5 | 4349bf9eba7ef3ddd81cb3d941720d93 |
|
BLAKE2b-256 | 992b6456123b15b9abc9fd217e164afdf5088520270096af2dd6f476d3416d61 |
Hashes for realcugan_ncnn_py-1.0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39f64a42c9ac7770a9fa9a04d773db7e052641aa8d092bd8a9f72e200adde0f4 |
|
MD5 | 5583923284d33d6c75cfa9fd7ae25fd4 |
|
BLAKE2b-256 | ca2fbbad8999db3e95171d914f42c2a78d292e1ffad2badd7b6b1261cdb63ada |
Hashes for realcugan_ncnn_py-1.0.0.2-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e19204fe42334833b0ce98b537d278ecd349b4c58f87fc3a19ec6cc62528bac2 |
|
MD5 | 051a2745d87ef8987013a10d9ba3f937 |
|
BLAKE2b-256 | 1a77bfbedd9c5480187ce644f27e6ebae55cdae01e9af9879e42f522e53483d1 |