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.0.0.3-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba82d6ec8a30bbe54f9d878b5f0d68806696c366ea9a9dbeebf0af9e56e56ddd |
|
MD5 | fbc7225c5889c2fc0f698bc81fb23948 |
|
BLAKE2b-256 | 6e9e273874e5c3f79b519172902dec910f58d2d95ceb718f63484b4e52f43b5e |
Hashes for realcugan_ncnn_py-1.0.0.3-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64314599d78fd85214801bd20c0703f2cb87043b51e2de972c0ffc4a3b7a90e5 |
|
MD5 | 3a58524bfaea03cbeac231812b647420 |
|
BLAKE2b-256 | ce5c2d4d45fa74ffefc97e00413058ef1ae81c51531d21359729f5f4ac2073a3 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9f791d4018362358770014a23aa147c05bb35d5f13634650a68767ba06eafd2 |
|
MD5 | 8f14a4e699a1eda28623f8a03b879a11 |
|
BLAKE2b-256 | 29a2fd61189c32b6285fd549f5a9fce486677a2a696b7069ee5b92962fe79317 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f93a596af0886176bc74b476bb39d05b459a95447886dd2802476b2c8a9ebc73 |
|
MD5 | a165a47bb3e37bfd47e80b67dea91d17 |
|
BLAKE2b-256 | 3c5a4efcc807cae0204ae371d3d4069843f77ad99065526c4a0e1980749a1d62 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbc012cfdd6567ab7980d3324cf20ea72ad2fa126a54df11e89cce5497510fc5 |
|
MD5 | 4d8130c272eef81d94269e441bc62f20 |
|
BLAKE2b-256 | cdcb737ca5a2df61e0d9361283751f8f7325080ddf444e66607e62b8bbb95724 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d0cdf1de6ee619ba5abee900eca7faa4e8115d14d28ecd4b4d9c05a062801f6 |
|
MD5 | 3a4e5da1258010e4044672550153d727 |
|
BLAKE2b-256 | 127b5b84f51f8c530b727b4ad1a807dde89a5b74065c8de9d492f686f7c51f30 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba3c84ae16fb1bc2180ec3301dbe79ef836bc9bcd3cb902962367cbd17b187eb |
|
MD5 | 1f0abf48b34cf9909192127c968c3325 |
|
BLAKE2b-256 | ea9c871c0a0d953e2ede058219db7cf2e95106984a4eebfcaf595e8397d00b26 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4285d14a020bc87e82938542ec7bca5281b3d595713e7b9dc636ef9aca10c409 |
|
MD5 | 5447d457cf665a5d7b9248bcb9a8cc71 |
|
BLAKE2b-256 | e5fa61049c472114b6a13c95636b2be8f8cf8b5988c14041af55aed91f4a4a05 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76f7da371a64f2fd9085da836314ec30e1ffc63a9d7f3f5eef08f6a4433f198e |
|
MD5 | 8b2d4979cd608184330419ea17576c41 |
|
BLAKE2b-256 | a5c0771fe0943fa3bec50ebc276686ba759c40acbc3a6a534025115fa4fec7bd |
Hashes for realcugan_ncnn_py-1.0.0.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 825d0aefdbfdfea5a7e463f66ce9c14f5c08cf47cf16ac22469632e2f67866b4 |
|
MD5 | 5e0d7fd867de36c61cf378086bd52a61 |
|
BLAKE2b-256 | d791138f451803f10836c9a439b0f137af143a197e9d6cba3d867b6aa4b1b686 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 809ded824b7e6b0cc544a4652d0c211c0cfeb5740dccc44bb1ab4f672fba507d |
|
MD5 | 31d914af4c5e871586586eee8e118f4f |
|
BLAKE2b-256 | 7996f154ba2951344e7355eb22a5aff860e35546b9b74b167517ee5894f3edbb |
Hashes for realcugan_ncnn_py-1.0.0.3-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1edd867a8896026ca25fcbdc882be857ce25dd3b6fa4b31e87975197ead3d236 |
|
MD5 | 0ea6e3e6a00f48d39f4db531eb0b4e23 |
|
BLAKE2b-256 | 2dea47ae601eef769d2ab4dfb008f0876ce3683646f565a6f0f21b4b67903afe |
Hashes for realcugan_ncnn_py-1.0.0.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5fa135d13da35607fa6a121923905841a1d03d86bc2a8b49bf4012e6a892600 |
|
MD5 | 38ea18b4c2d2513b852d06f272c7487d |
|
BLAKE2b-256 | 7b7252a2fb9b662b1ee57b96e83a1294fc086379bc1e2594bbb60e92b153c623 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85449a584ff60bcbc25d2464f8d8233f8b82096aba298b52ca8e30928126d79d |
|
MD5 | b474dde8d706385e49d60f5374ab8d7f |
|
BLAKE2b-256 | b48efcc287af4042597031cb7b1213f2c3c88a40c87a84d1cd613b3228d07290 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 193e855d970a77f795bd55ff6ff709539c798fd63b69574f11679df6af5b137d |
|
MD5 | 21be82e64599c76b6bccce7e3b65f36f |
|
BLAKE2b-256 | 975c7438c368a8ba9d9a4f12e2c3af0171d4d20a9bd1b5135b7ff025eab02a00 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e8d1f970dcb93792dfbc0711f5bdf75895c07fc1bb6e49a1b87df838987737e |
|
MD5 | f811e49b05156a1abac804a1dc1932db |
|
BLAKE2b-256 | 1c580c0c0f180284f246172f820c3bcdd91a4e3264178b59eb7975ec7bdc64d4 |
Hashes for realcugan_ncnn_py-1.0.0.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45807af372646720fafdbb4bf0c13dbb8655ef3ff651f620b5d6dab8e1f2c129 |
|
MD5 | c85041905a7c495e77602560c84544be |
|
BLAKE2b-256 | 0ab7cd5e18091ddbd7992b430c4b90d06c10df80f0958922ae1d44e63ea9dbda |
Hashes for realcugan_ncnn_py-1.0.0.3-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4d3e4a436e1d9861bfb318dfce0a46d9d24be4f4e790b6a75e33f8849481d4e |
|
MD5 | 54a0937e9d65abda254b3af258e3bbfe |
|
BLAKE2b-256 | e8c500d7698d4f0ca09a8776faccf7579d3bf2999018d0b7f1c5ad02519efc4f |