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.2.0.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 366e682c97256b6d32bc679c72413fb34769f9710cc23108b950e1a18abe640e |
|
MD5 | bc5a1aea413a5a5a475402d510f7a99e |
|
BLAKE2b-256 | 3f3705eef9f12c860a8e3189fa3a1f0506f7c4ab9f2fc47103b105f8fb9ed8bd |
Hashes for realcugan_ncnn_py-1.2.0.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dd2c65b5aedaf5f1a9ce4e1172d024d2dca63abf64247a626e06ca2230cefd7 |
|
MD5 | 2570b32ca9b2e22e8f30f92561d6b12e |
|
BLAKE2b-256 | 8eb1807f0d0d48d8dd42c2a6639801dde32b64b50210d5c683ce38df9cea515a |
Hashes for realcugan_ncnn_py-1.2.0.0-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fedbae07f1e85a7afc7be436c412bd8140496e2e8ade9560fa422f3441bec13 |
|
MD5 | f5aa9c6b2e11462a507d2496cd4e8226 |
|
BLAKE2b-256 | adf4b2933e858fe42273f09c0a9deab3cfae4e12d6c3a8c9b536eceaaf73449a |
Hashes for realcugan_ncnn_py-1.2.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32cfe1d6839c3e97dd179d2790a87f3ffafb38c7eba6a6abdcbc4b04b2c38f58 |
|
MD5 | 1732ae5f227b143fadea5a8723b9a394 |
|
BLAKE2b-256 | 1cb0b731d14cdaad6aa21b57cca7c8370bdb6014aacb9562e9ed5c4c4cade8a4 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b99e788292ebd86892f1086d9e66fe5dd228ee1ebffd253de7870ebecab978f5 |
|
MD5 | 0a67667ec66bffc8434af60d0094f9ae |
|
BLAKE2b-256 | 14d3c19404cf45d6f810a0257f3b52ae15a6c7f23a99650b94778d36600a8a13 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dade0b3ddb1a389de4987a2ee317f781905dfec87a6da822c97b5d07e0accde |
|
MD5 | 332d5e7e2c73a34abff437db09e9938b |
|
BLAKE2b-256 | 23177356f3d94d34a3e1d821b88dcb2ab5eb7f9fe0f420e6b3f79ee0184f0d7a |
Hashes for realcugan_ncnn_py-1.2.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7f571cb2953ad6c37d6d4c74868e8434642a02c8e27667625d30d60e7614f60 |
|
MD5 | 8efc74c0527fa185386e87094767a756 |
|
BLAKE2b-256 | 6080bfdd4acb0893a24df70e48d0e867fe05c5a64f83906c95265294c2be8285 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4a21b5b0deec50f657390419cf2c919484ac031c28a5b3869f716804fb04b91 |
|
MD5 | 84d47b8ba9a75f0ca873368635bdd35b |
|
BLAKE2b-256 | 4a9da98ec92aa726a2e10dff096543347f9aa88fb231c5554a7c14afb9757109 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eff74316a2bb69edc097e9d8630033bc67d71c8ce2c951f1670f8f4220a411d |
|
MD5 | a395c18f9760f36ebb0bf2a4486e9f38 |
|
BLAKE2b-256 | d501380ed6498285d8c578697e9ddbacc31511a4390ef80c26f62778f27afeed |
Hashes for realcugan_ncnn_py-1.2.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3889082551b737bb034911da43a7433bfe4abeddf00e88d87a03782a90b1ab5 |
|
MD5 | 46677ff2f7686c73fafa6b4d011dbb3b |
|
BLAKE2b-256 | 417e87b51fb7f3539bbf4d3902d596ac69dfb347df82ba74ca3b908f0217c3db |
Hashes for realcugan_ncnn_py-1.2.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 230ca5ab3b1191adb3c2e536fd795101062db86b84e606073f62c22780fc250c |
|
MD5 | 1e1fb694f412b41ca1ae97a6eddbc6b3 |
|
BLAKE2b-256 | 8883c45491b5ebca9ec3634d35bd8d9fd02950a8eb268bf23e21514a90b35c52 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91e6b1505de0c23d6c4b216e1cd219db0b7aa2e189d8b1d5dac343252f086735 |
|
MD5 | 1c0847bcde76cd8df2232ecd8a330567 |
|
BLAKE2b-256 | bacc8e53ae8232e83cb136a7577ca23ecb11117fce630ca8402842d9cbd156ab |
Hashes for realcugan_ncnn_py-1.2.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07db6e188a745c681b3a9d77339ae6fb60a627d7c5ecfc01557044badef1364d |
|
MD5 | 1bb27ad1f882c93b508a7bb9f3d3215b |
|
BLAKE2b-256 | 0becd1d5765e74cfe98bdeaa1fe603148de2e093b92c3012d8a4bb71bb1b0600 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 863e0dcb9910f0097197edcc99e8470718c425ed0bf650a57b270d8856ad74b6 |
|
MD5 | 6809c2a6395ab0a50fa7f80fad40a84e |
|
BLAKE2b-256 | 6e51831d04bab8c3cbc0aff3649c99e757fae09a3a555e813c18d6efe64e6ab7 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56fbc2699ef7ff4b4e41e7ec06fb569d39822e685fbbae62ea129983876ef7a4 |
|
MD5 | 5ddaac049814edd47b304e8aab0fc68d |
|
BLAKE2b-256 | bb93aeee0666ae4fd2372ceffb5baa24d8d8d09e2049091452be43c97d75a629 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ad52588857585d85727a54cf0e099afffd1b5215ee4559c2d391359716c87ed |
|
MD5 | 388a849c0142b356dd1e8454329328f6 |
|
BLAKE2b-256 | f414470d85833df98dbab8c3a0777e1ebaa7c621d621138ac08667ba2f935fd6 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be31889b2a85e9df0298fcdde68e31e4f4b1a54c41cf9cafbb3ba9ad5f68295b |
|
MD5 | f5b8701db1a0314a85f02629b204f9f2 |
|
BLAKE2b-256 | 933cb510d3b313c6f7ac3f7d54027fa3699c0b471d10dfe0faae26f751ca3ba2 |
Hashes for realcugan_ncnn_py-1.2.0.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e636f3fb361d945bc6fedc84f5b5bfc00b9ad521f52b4ca888b1be9d9fa3aa8 |
|
MD5 | f868146c022dab013785baf90824726d |
|
BLAKE2b-256 | 1d9293a0871be3f46f7ab9b010616547ce4108a3002ff4e0e4e2c19a98d95b1f |