Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

realcugan-ncnn-py

Python Binding for realcugan-ncnn-vulkan with PyBind11

PyPI version test_pip Release PyPI - Python Version

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 Status CPU (32bit) CPU (64bit) GPU (32bit) GPU (64bit)
Linux (Clang) CI-Linux-x64-Clang — :white_check_mark: — :white_check_mark:
Linux (GCC) CI-Linux-x64-GCC — :white_check_mark: — :white_check_mark:
Windows CI-Windows-x64-MSVC — :white_check_mark: — :white_check_mark:
MacOS CI-MacOS-Universal-Clang — :white_check_mark: — :white_check_mark:
MacOS (ARM) CI-MacOS-Universal-Clang — :white_check_mark: — :white_check_mark:

Usage

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")
# 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

here

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.

Metadata

Release files for realcugan-ncnn-py 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for realcugan-ncnn-py 2.0.0
File
realcugan_ncnn_py-2.0.0-cp312-none-win_amd64.whl CPython 3.12 none Windows x86-64 Details
realcugan_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl CPython 3.12 none Linux glibc 2.5+ x86-64 Details
realcugan_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl CPython 3.12 none macOS 11.0+ universal2 (ARM64, x86-64) Details
realcugan_ncnn_py-2.0.0-cp311-none-win_amd64.whl CPython 3.11 none Windows x86-64 Details
realcugan_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl CPython 3.11 none Linux glibc 2.5+ x86-64 Details
realcugan_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl CPython 3.11 none macOS 11.0+ universal2 (ARM64, x86-64) Details
realcugan_ncnn_py-2.0.0-cp310-none-win_amd64.whl CPython 3.10 none Windows x86-64 Details
realcugan_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl CPython 3.10 none Linux glibc 2.5+ x86-64 Details
realcugan_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl CPython 3.10 none macOS 11.0+ universal2 (ARM64, x86-64) Details
realcugan_ncnn_py-2.0.0-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
realcugan_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl CPython 3.9 none Linux glibc 2.5+ x86-64 Details
realcugan_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl CPython 3.9 none macOS 11.0+ universal2 (ARM64, x86-64) Details
realcugan_ncnn_py-2.0.0-cp38-none-win_amd64.whl CPython 3.8 none Windows x86-64 Details
realcugan_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl CPython 3.8 none Linux glibc 2.5+ x86-64 Details
realcugan_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl CPython 3.8 none macOS 10.15+ x86-64 Details

Total release size: 717.3 MB

Release files / realcugan_ncnn_py-2.0.0-cp312-none-win_amd64.whl

Download URL realcugan_ncnn_py-2.0.0-cp312-none-win_amd64.whl
Size 44.9 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
6567dcb1e00994d8ac7dec4e88abe0d0baf045c5e6093c70ed942eb585607ddc
BLAKE2b-256 checksum
How to use checksums
8bf19d111be58d161ef898561dd966c694b125286b77c07761d20f5c8a60553d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl

Download URL realcugan_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl
Size 46.7 MB
Tags CPython 3.12 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
f576b86ba4311d245257ffc37997d6d0ece68dbfafbe166011a179e86b333ad2
BLAKE2b-256 checksum
How to use checksums
c4be880021f75ecd08fe5d263cd6cf42282d183e38907894b17bb767170170e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl

Download URL realcugan_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl
Size 51.8 MB
Tags CPython 3.12 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
d4426769a7079f6cb2276eeddb0e18a0f77a3d0c3e02426b75fbf2ad15e4703a
BLAKE2b-256 checksum
How to use checksums
4a7861f716a4c244950b10fa0f191438d82529dc2284c7beb4b969f20dcb8114
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp311-none-win_amd64.whl

Download URL realcugan_ncnn_py-2.0.0-cp311-none-win_amd64.whl
Size 44.9 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
538cb74c8d2fcdc014f234aab693afcf0aa2eab3efd85dfb71be273f1e2654d6
BLAKE2b-256 checksum
How to use checksums
1a605309933d6e6d30ad9d065081e7652b7b58842bf8d91a894e7534d60d5e72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl

Download URL realcugan_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl
Size 46.7 MB
Tags CPython 3.11 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
223525ee750d5cf7679213a5891b16dbf8ffe2f84e8a28b6e5e7b5ddddace60e
BLAKE2b-256 checksum
How to use checksums
4866fa0ed0c0ea1f5f8f492b1df5ae342ea959fbc505a08cfc43db1c3e8b0253
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl

Download URL realcugan_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl
Size 51.8 MB
Tags CPython 3.11 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
255d612006d06579ce67b4943d207650acd66e9b677abb8b42749f91179a0448
BLAKE2b-256 checksum
How to use checksums
9b911223b0eeebd1513c4738129e860625da8fb5be6e1d813a930864ffa3718d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp310-none-win_amd64.whl

Download URL realcugan_ncnn_py-2.0.0-cp310-none-win_amd64.whl
Size 44.9 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
d6af5d90b340617148d15afd004ec31fa32247e93d7132e9a6decf656e0ec355
BLAKE2b-256 checksum
How to use checksums
24b799df00b707df08e733ab3ffbc0af841ed90d24b0be93a441baea461805e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl

Download URL realcugan_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl
Size 46.7 MB
Tags CPython 3.10 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
66891b44a8a09936276d5f629a59f14d7f136289989549b66dfabbb5c8c214c8
BLAKE2b-256 checksum
How to use checksums
396bac1dd516fed8f107aa1a333423e2f5405cc1cf7746966b484edf3460580b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl

Download URL realcugan_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl
Size 51.8 MB
Tags CPython 3.10 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
1ed7ee33daa114fb649378097be3a3b246e563a96a2a66569f24fbbe096ac55e
BLAKE2b-256 checksum
How to use checksums
e9396355d66c8ec35df5d4abf7899aa4594b6c030a5cc5a0fa3519fd469f4043
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp39-none-win_amd64.whl

Download URL realcugan_ncnn_py-2.0.0-cp39-none-win_amd64.whl
Size 44.9 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
8bb1f8da181f0fceacb8287b2e38c092c740bb9d6a6909248b9c87c8b69c93c9
BLAKE2b-256 checksum
How to use checksums
f153a1fd0f9769cd315b1fa1dd0fd5fe9207e429fcf506ec026006a0f77b357f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl

Download URL realcugan_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl
Size 46.7 MB
Tags CPython 3.9 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
c603582092b137951cbe84dc7e749d53c81326fbdce879fdf9739d2c4cf014fa
BLAKE2b-256 checksum
How to use checksums
98f7e10d4e375b34aa20a730875517ab687a33a6d5ec64934d1a54ade16a5c53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl

Download URL realcugan_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl
Size 51.8 MB
Tags CPython 3.9 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
c05dd7f1f7f5cb9fbd66efc5ab9606f9a3fef352dd9eaa37b9a95030af4cba2f
BLAKE2b-256 checksum
How to use checksums
63add0100c14bd673e577c9587ce78ca3238ca40ce9ecdf2124a433e5a373859
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp38-none-win_amd64.whl

Download URL realcugan_ncnn_py-2.0.0-cp38-none-win_amd64.whl
Size 44.9 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
65d56be23ad7db26ea9cbbbd73990eaa44a43758a657b620be490177c4874eeb
BLAKE2b-256 checksum
How to use checksums
531a4ee6dde1279eb86542935881d26c6e0375d4e4455867d453c34718ebbf1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl

Download URL realcugan_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl
Size 46.7 MB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
ac02a50e8cd2332d7f9f3867fc748af03af3d78a47500e9c8b68588c5d840775
BLAKE2b-256 checksum
How to use checksums
8c3fafc74ce3561bb0e1a6fb902dce1a4d892df5368dca7b42d74d0e6546e041
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / realcugan_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl

Download URL realcugan_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl
Size 51.8 MB
Tags CPython 3.8 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
c38688c1dc15f28e2eebb6375861fdebb4fd913958d80ccbf2eb415d3e578f19
BLAKE2b-256 checksum
How to use checksums
102c78f5ca06e446458688e52a15493e992d7ef8f22c79cc49c7a3d98c15d3e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page