Skip to main content

No project description provided

Project description

waifu2x-ncnn-py

Python Binding for waifu2x-ncnn-vulkan with PyBind11

PyPI version test_pip Release PyPI - Python Version

Image Super-Resolution for Anime-style art using Deep Convolutional Neural Networks. And it supports photo. This wrapper provides an easy-to-use interface for running the pre-trained Waifu2x 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 waifu2x-ncnn-py

For Linux user:

apt install -y libomp5 libvulkan-dev

Then, import the Waifu2x class from the package:

from src.waifu2x_ncnn_py import Waifu2x

To initialize the model:

waifu2x = Waifu2x(gpuid: int = 0, tta_mode: bool = False, num_threads: int = 1, noise: int = 0, scale: int = 2, tilesize: int = 0, model: str = "models-cunet")
# model can be "models-cunet", "models-upconv_7_anime_style_art_rgb" and "models-upconv_7_photo"
# 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), 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
waifu2x = Waifu2x(gpuid=0, scale=2, noise=3)
with Image.open("input.jpg") as image:
    image = waifu2x.process_pil(image)
    image.save("output.jpg", quality=95)

opencv-python

import cv2
waifu2x = Waifu2x(gpuid=0, scale=2, noise=3)
image = cv2.imdecode(np.fromfile("input.jpg", dtype=np.uint8), cv2.IMREAD_COLOR)
image = waifu2x.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)
waifu2x = Waifu2x(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 = waifu2x.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/waifu2x-ncnn-vulkan - This project was the main inspiration for our work. It provided the core implementation of the Waifu2x algorithm using the ncnn and Vulkan libraries.

Waifu2x - Waifu2x is an Image Super-Resolution algorithm for Anime-style art using Deep Convolutional Neural Networks. And it supports photo.

media2x/waifu2x-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

waifu2x_ncnn_py-2.0.0-cp312-none-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.12 Windows x86-64

waifu2x_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl (36.0 MB view details)

Uploaded CPython 3.12

waifu2x_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl (40.9 MB view details)

Uploaded CPython 3.12 macOS 11.0+ universal2 (ARM64, x86-64)

waifu2x_ncnn_py-2.0.0-cp311-none-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.11 Windows x86-64

waifu2x_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl (36.0 MB view details)

Uploaded CPython 3.11

waifu2x_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl (40.9 MB view details)

Uploaded CPython 3.11 macOS 11.0+ universal2 (ARM64, x86-64)

waifu2x_ncnn_py-2.0.0-cp310-none-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.10 Windows x86-64

waifu2x_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl (36.0 MB view details)

Uploaded CPython 3.10

waifu2x_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl (40.9 MB view details)

Uploaded CPython 3.10 macOS 11.0+ universal2 (ARM64, x86-64)

waifu2x_ncnn_py-2.0.0-cp39-none-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.9 Windows x86-64

waifu2x_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl (36.0 MB view details)

Uploaded CPython 3.9

waifu2x_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl (40.9 MB view details)

Uploaded CPython 3.9 macOS 11.0+ universal2 (ARM64, x86-64)

waifu2x_ncnn_py-2.0.0-cp38-none-win_amd64.whl (34.6 MB view details)

Uploaded CPython 3.8 Windows x86-64

waifu2x_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl (36.0 MB view details)

Uploaded CPython 3.8

waifu2x_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl (40.9 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 5b480bcf34e8ed82bea0fe1b9650f63735351c5ada60a09b64bde1914dc79233
MD5 431cea66e7e98102703ed681edc3cf5c
BLAKE2b-256 86a53acbd64f42abb5f46c438d2a61560c01bb22ac7f8cd80cc1ca0ff4cc187b

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp312-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 70db561fb00c2dd9b184c3a52dfb2a69f4a0eebf0cc9e21aa6ab7fc4978995f2
MD5 0fb224c1f3724240413ca41c816b0537
BLAKE2b-256 7fadce2dff93a14f46d9d18d725b288d8284572bdbc498d30fbab4b55cf5a861

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp312-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 b2fcf0887fb489779aa24cc6124f34b92633108356d86e699b797b96bd530b1b
MD5 90bd565deb844eecea3106320eb0524a
BLAKE2b-256 c58b474088dfeb3051a7bc865746c76c12e7ab2629cd191703990bda71574ddc

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 0a00d709ed1f666dd5d0be4eae8a66589ebe991513a8409e6fa7d93efe83b4ec
MD5 f7fd397f2b3cd54df2b7b5555a4a8d58
BLAKE2b-256 51b63e99bd679d05152c4aceda57e374796b69511fffd2ba79ee754bb76aa09a

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp311-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1f991d6c066bf3f5f038fc9ece448ad23f0d91cf75b62e10870e645c29a05d7c
MD5 fe9119dc22e5e1a10eaf608f52ea45bb
BLAKE2b-256 a2c79202b1223c4a0dd651c9b7aacd774954cd50bd6ec8e786ec3e92769910b3

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp311-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 2e76989552a70e62dba24f017e4ec15701dfd22e5865afbdf6b9aa355b00ffe2
MD5 2561dbe02552aca27a45c9a9a284c5dc
BLAKE2b-256 e20ca519f08fef390bb5e3843e21e7cf3ffc283e6267f217b01520b56b20dcb8

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 56380d72bf51604f57dd695d9632fed0eff1d6e97339390b6ba2fdab5a32f7b7
MD5 6d83b7fa3785b0feef5fc8b8e3e31ff1
BLAKE2b-256 cc630b4ffe36152ee2826f204eb787bbf490f7aab918beb101a4d89b562c6a45

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp310-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 89514098703361aff0e787f2d62c2786f5c637c98ff530e68079253422baef62
MD5 dfd04cb24a8698095fc2256329019c51
BLAKE2b-256 9c1e2d3143d0823dff2644c07e7eeca0414cc9112b37a1a8723393b1127516a9

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp310-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 18584cde42ce417df70001c0dc8c8763401b0e20ae57a2b2fef5edbb4f4a8ca9
MD5 464fca16aeb27ff9e9e2f833094d22c5
BLAKE2b-256 1999a6f8cc4fd62f4deabc357d6aded681af94278e3063a8477f213bdec5055c

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 b546242b14b6e2132097a431aa902df634e44efad8101c46d034f0f8779cfa5e
MD5 a02bc1287840227b46b07afcbc00a4ea
BLAKE2b-256 82e57f501a23ef2b54564ca6b320ff6440719ee0694b0a619b2acf28b8f09cbf

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp39-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3b08ff93ac1382386977d95f07ab099892e45e1ee734d7b462e70cd47ade28e6
MD5 db71c2f287d985f08f9ef46e471c6b98
BLAKE2b-256 a81b0c7c43a79b3c04ea2c07121ac6efafe19e705340862aeb147937ceeae025

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp39-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 7ac6f2bdb6709c7459e72b657c151d2943b95d3af5257c915089a33db8cc6cb3
MD5 c2285c34a916c73b49aac771394428f1
BLAKE2b-256 cf6b40009d21e47935982f2015908a4481ee11939cafa639eb24f6dc137165a4

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 7bfc21c6c09629d1cca3148b66e79384fedcfc28294fddab1eb042af471f591f
MD5 5798c2455583be905d266433c08c2ca2
BLAKE2b-256 0386bfa61e21b38208a44da506597fb4ce33704f5fd9aba589630b2c5f1fc0c8

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp38-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2c6f5e2a9f0cee02d938f83da2f6e4730ce3cd2d2d9553044cd3963c009ce956
MD5 dc0399b41531e9cd931822d8a80236d6
BLAKE2b-256 6fd4144f3615441279b202408c953af30e669123925c548bf2fc0e41f0ef6c86

See more details on using hashes here.

File details

Details for the file waifu2x_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for waifu2x_ncnn_py-2.0.0-cp38-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1e377ec0734c3fa9ae1a21fa26fc33e1408ee1a1e34863060ee7d3dfb55677d6
MD5 2da11f326157862fc10098569aa4c766
BLAKE2b-256 1b77184a325ea68aa81a0b4069c6ea13ddebb0da5c25907d4bf488e450ecee73

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page