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
System | CPU (32bit) | CPU (64bit) | GPU (32bit) | GPU (64bit) |
---|---|---|---|---|
Linux (Clang) | — | — | ||
Linux (GCC) | — | — | ||
Windows | — | — | ||
MacOS | — | — | ||
MacOS (ARM) | — | — |
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.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4c3996343dc6215a12063e36eec13ef24624df19a5464b86b686d903c866c48 |
|
MD5 | 84bd9e104d689478604004baa6e52601 |
|
BLAKE2b-256 | 313196b27134de78b7c98d16edddb91d6f5d171e2e0007f22445e530c5f39755 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8b3ad1ae81f8a805524279c624a0df031984afbd4bd4697f728f02ff212b13e |
|
MD5 | 9f93552c014c1373a43310449993c17e |
|
BLAKE2b-256 | ebca6032b82a10523195cd60674d39fff437bc183f571b0b9c24641ced4fd4a9 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bfa78f72916fe27212f4cb8e449cc22d10b7897761474b981c13e2079dd39f3 |
|
MD5 | b4560222eac46bfd2ecd0e6f4677a132 |
|
BLAKE2b-256 | a6ffd88d543ffd67b6e244fb138eb7753cdc3de1e0c47c0edff5a12921af8b92 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97c8f8f2bcda573281ebbba68652a8c3b893b08d6f744f72d55e8a3ed32cd616 |
|
MD5 | 91d3f230d0bb7a2b2eb66065f8ada0ff |
|
BLAKE2b-256 | a769e76edaff629302157adefb7cdb37b9a762c167744c5b18dbc9639ec0fdb9 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0efcaa9cf4aef10c30f403db0fe8f28a5515b3165f9fc0b03c1a1bbd11850db |
|
MD5 | fff3505602c15a22f3ae26a339f723ce |
|
BLAKE2b-256 | 925acc06d28a1681382a351c410540081003c9856b945418d0563d4a47df4109 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1fda841c51bb22a2afea899c31c0b48388ec1fe9cf240385a2cb3b37a60aa35 |
|
MD5 | 0a1e6f48ca8b04744203bdce8b28271c |
|
BLAKE2b-256 | 4db5dda073428f26620b9d30a5393713e96ce2fe6bb80936b8e0e5395991247a |
Hashes for realcugan_ncnn_py-1.0.0.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03f358ee3d6fd364573f3302ed74ce87e0869cd11a7c11cfe4332dbb21c69e5b |
|
MD5 | 46157143da2c4821dfe6f9fa30c699f4 |
|
BLAKE2b-256 | b1c0d9b54dffe0d80fae9a68d5e3b349c422a1a9b6b64c2aff21e0ba2060146a |
Hashes for realcugan_ncnn_py-1.0.0.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10770d7a0a578f633744ab69643baf926690167d5f1996df9d8fc31b9033d079 |
|
MD5 | 9f06b12bda1c6702447cc32b059730ed |
|
BLAKE2b-256 | 5d94091eaa3b0bbf078c358acca48fc5839f23705c99e0548192a873e6b9b8fb |
Hashes for realcugan_ncnn_py-1.0.0.1-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0896c1d5824893ee84c6f9b9cfd178e5fa354ce3b20db60a9334bbe23262533 |
|
MD5 | 8cd69f26df11656e2f84f7012e098e34 |
|
BLAKE2b-256 | 0c851fda17a957e3b83664f6f56324206c35d2b9025cb6e8d29f6c42f3cfae2d |
Hashes for realcugan_ncnn_py-1.0.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9a75796e38af3fb92c22f4fd35504467f34a66016cd6b9ab7730c3f306b53df |
|
MD5 | 7344d7b92d221240a3fb98bdc1024f92 |
|
BLAKE2b-256 | 2552c33c6f5a182ac156746b2e92c63e215fba820e665f183496d8e9c4336674 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2d330ab9ad66f56e97cb8f1d94f30f91feb69c2fb9fe6d2f12add13358ab06a |
|
MD5 | d81f89b0b8b45a60104a589263490d01 |
|
BLAKE2b-256 | 244780c4886bcf5ac35d445ec7e6d83a37f2e5da90c43c7c9b8b5c16f4ccef99 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dc119efdb4b3d96a2ac294965d84c889fd3107eef7045feca68dcab68058d46 |
|
MD5 | 87746c61e6c8fd5d8277fe930f67d3af |
|
BLAKE2b-256 | 727f559b4be19667979b6e3c9ca06e07bd0e7838c9d466bbf0ceb91862ee6168 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84185fc18afab0bbeb057ee244dc4d19946790a7b2580c565503f3b3423c1c88 |
|
MD5 | 789da5d16774f2399259f952f2e752f6 |
|
BLAKE2b-256 | 67dafba875eaf042f5958642a33cd6b66aff21bf2f1b8df5dfd4d98c0f622d51 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 876d2954e443b9d1faf6c6ce8dae611927163e23b26fa45eac6aa606d1cc29b8 |
|
MD5 | 461f25e23968a1a36cb8aa41019a347a |
|
BLAKE2b-256 | 53af150dea4a5d90dccd475499e494b056b7fa3f5b78f2e7ce9c7f0f283ac663 |
Hashes for realcugan_ncnn_py-1.0.0.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f287e7d1335081d65b0384950a3c18cdd23d5ddedddd8f33530926e33db2b817 |
|
MD5 | 4f2e911a4610f33e2e329b726542c3a0 |
|
BLAKE2b-256 | aff64af9fee592cf0b44acfc07c4335a6d7192282009f41a35034c4dce02606a |
Hashes for realcugan_ncnn_py-1.0.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36216680868bb45467d885bb67f50c461f39b969575ad4c1d5cecd96e544389a |
|
MD5 | db6451e0489eb1bf9edf2b6657ebf654 |
|
BLAKE2b-256 | 16d7b78acca4fe50e5726930fb4b9ff0c73d98ee8f21a0f0310f7e194a7ed12a |
Hashes for realcugan_ncnn_py-1.0.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e1d1b9030f5b147d1bcb3caa3914310fc6e0b46ecaa668ced49d5c0ab78afdd |
|
MD5 | fc41f4b06ba34b359128fe27233e0b9e |
|
BLAKE2b-256 | 161d5d4a7096f007e3490c28d004f1aa269c3983dcb182d69a7e25b3f56d3c3e |
Hashes for realcugan_ncnn_py-1.0.0.1-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e1ca0ccbbc283028a03de4fdd878f953513b649a50676b5190d457a974b1555 |
|
MD5 | 4a4842662143991325680bc2d1b23184 |
|
BLAKE2b-256 | db336c9c0f996eaf0d6a0eab63db273cebd3a9c4c8723f90fbe19f2e25d3192b |