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.1.0.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8781ece1aa1cb43089017bfe155cc7f4b054fd91fb5704d2dce7a199c82e8807 |
|
MD5 | 8ab6ad6473b5919e86ef0581347766e2 |
|
BLAKE2b-256 | a297eb570e9da69dc320a2f430de44be10bf85ebced42086390095a40a912705 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b791651484919591c965e662809bb1335b9b392af22948df370f5fae811a7fcf |
|
MD5 | c17862161a5aae572c354ea8d6c785c8 |
|
BLAKE2b-256 | d7b48fa8df2c02c83b34c9a7d64b621511ff9d0e4de8a1b200912c0fadfc8e65 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aa00a02cbf032dbbf638e27729cd1d44abd3a1b00381a6da9dd618c4b85b6b7 |
|
MD5 | 75987f25d27988eb78a1f55304c098f6 |
|
BLAKE2b-256 | fa2137b55918884b3c0fc0c22dc2adb2610d93c7593d9c47f8e97189f0b44f3b |
Hashes for realcugan_ncnn_py-1.1.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfc49c15bfd1c2f05b24757cee015dc1e502978ad4e22f8b0e2588e83eb02ca5 |
|
MD5 | 79f355963d190a1f1860fc5952f76a2e |
|
BLAKE2b-256 | f52e1489d181c2bf6766fbc3658e5f1edee419fdefb2ea8db9aa6943674a2ac3 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3338006a90a5010abcf836a07a1a2aeeb22f7bbcc34b1aa64da0b443d61c6639 |
|
MD5 | a5f95ddce19c6e2895576e2b99f48ad6 |
|
BLAKE2b-256 | 9e2b2c213e5120fae3f5b1277f3dc0e7faaafeb2ae420cee27869607e851ae2b |
Hashes for realcugan_ncnn_py-1.1.0.0-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2b47bc8a92ff5eb9d39a7bc52e5446bb19c661b820cfab205b7333dc10356a4 |
|
MD5 | 0421bc073c8c48b4e7966087624ab4ba |
|
BLAKE2b-256 | 46219a7d5b84aa718d7b5b7d512cf6db63f044e003a89922b383543421d3fd82 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57619eda684c9d756e17075c6d6b672177105a9fe7c609dba1bff2694a7eb2bc |
|
MD5 | 43e4facb649515e27000ff1b74311f85 |
|
BLAKE2b-256 | beaa462f9169662e0b587e2c7e17082dd0de6f804909222dbbbbd1294a225f6c |
Hashes for realcugan_ncnn_py-1.1.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08455adcd18f0ada5a3691760f5128178a82ef9026f26e0def53ae7f51219a8e |
|
MD5 | c03bf32b8267939fa0c50621aad1c524 |
|
BLAKE2b-256 | 338a9a375ec54574f2ba98600184a14612fedc7f5d91acf35033b7897a794f7b |
Hashes for realcugan_ncnn_py-1.1.0.0-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cdea9efefd8b77b9e3b1306958d29640c9400a34fae3e329cddce65c1ef9cb7 |
|
MD5 | cdff6ac1e58b148da0c948fecb59ed37 |
|
BLAKE2b-256 | 9ab44583d03a5eb81bf0ceac14dddea9f351007cb03c88b9fd756907f98a0a92 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed473ef9167f535a7620c4ef7567883030811c5420c69865a1fbc70595b0daf9 |
|
MD5 | f20a1a41d5251a0689a5d28f0af2eeac |
|
BLAKE2b-256 | 1da2df925be7993d83fe12a35b006ca77a1e7b02ac69c996da82a0b065b7243c |
Hashes for realcugan_ncnn_py-1.1.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ea185be5d31123d8c80e81f0c747dd96bd8851f2b2534185a9505150f837f6b |
|
MD5 | 07eb4793caaf1b5dbdea38a824737a1b |
|
BLAKE2b-256 | 3e054b05016e61656be940f0a92cbbae95c3d51fc3da22970fa7c3dac0468259 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 613120e0a6ca49bf693961e82a134ea959e8ba2a4315d65fbe8de925c10cb2ac |
|
MD5 | da414d3151629447e5c26c17c87d58a5 |
|
BLAKE2b-256 | 9cc03c53ad0b3190d7ee210ed22ba8a0dba9c1f0d4248c819694552334728745 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e53c078a70dd15d6bec3e40a4fbdfcc1265ad10d209c1c12c09b93f84a3ac36b |
|
MD5 | ffd40f1c86083db7007e5a5b1981ed99 |
|
BLAKE2b-256 | 6753dab5b45bf66ae6843637d0d8c6531bfcf1f88b236cc0272290939568753d |
Hashes for realcugan_ncnn_py-1.1.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fefa1f4029eaff026e0416a3cd3d4193b7c14a7885c93cd68d2d73d3d9ad694 |
|
MD5 | 594b924d8414fb75e8c5d9e60b0cbafa |
|
BLAKE2b-256 | d3e93332fbef279cd793822b69ca29e4de71c7c88b1606bb30d08412d08a8dc9 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b8a19cac3e794a8619000e15890ebfdcf9b932cb6c130cd1ef3f9235af6e260 |
|
MD5 | a85138d6dbc2c7846f70c22933886183 |
|
BLAKE2b-256 | 8c5bdf3e043e9775f3c1118ce9bc57576cf36dd824aa8d8cf3a34ca111e72f16 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9530e00192986d9876cf9b43993cd80d3fec78ae7ec8b2c5bd090847391324a |
|
MD5 | 072a90a93f3e75f0ef92cb20027800f0 |
|
BLAKE2b-256 | 1c3507f3168338c67b25b954027235c0676d0d3d61b0f4f45fd01e62049b9a08 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f390a70377aecac4a870ef38f567745598a2025be0d0f1977e1967d7c215a6fe |
|
MD5 | 955526a4631f34b03e6ea37dafdc2e02 |
|
BLAKE2b-256 | ab51ef4f14d46bdc86505da87c2bbe4a1d24f290b56fa8d20e69bd42b1170271 |
Hashes for realcugan_ncnn_py-1.1.0.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0adf5af21b94d9e47303a6140f278de525dc2e0c573d81e284948c7c28f0b33b |
|
MD5 | 672f7bcc3ce356e9c5f2dc2f4961a068 |
|
BLAKE2b-256 | d25cf6522bbb18c3869e69d4ba81f35a7cbcfc39f3f1adbc79936b6edba832be |