No project description provided
Project description
waifu2x-ncnn-py
Python Binding for waifu2x-ncnn-vulkan with PyBind11
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
Usage
Python >= 3.6 (>= 3.9 in MacOS arm)
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 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", **_kwargs)
# 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
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
Built Distributions
Hashes for waifu2x_ncnn_py-1.1.0.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ba42a2db519ee484ab29462893642915bcecca1dd9eebe66e0db89cd2aef6dd |
|
MD5 | 59793c2e30cda5bc90d9a72cda392292 |
|
BLAKE2b-256 | a5a1445eacb2d2f418b2e682ba16b04de3f0501d09fc1f746b7acfa938873a59 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0dc28d2f0f105380392b1568989ee7b49a93e0835c77078cf963bc6139a3670 |
|
MD5 | 4665e7f5e117b424b14c9107ceec1d02 |
|
BLAKE2b-256 | 4f6383a635381ba02b5e9e2faf9ab8057166d934732804e54bf7163540bc387d |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp311-cp311-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c5a49ada9594c0da6b8fa64b7801093f0571a2ea8d90f34a95c76eaadb9422a |
|
MD5 | 06aa15c90231b07732176f4589b08391 |
|
BLAKE2b-256 | bd3bf4425c06f3145511f5213698b14bb7177f8e6ee3d9f5703b099ba964c6df |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3655c932834fd0f5ed7ecd6f6fafce925e2399550cb4b0ef6e2805eaad8b1103 |
|
MD5 | d8ee933c05e7d25ced3de64b1b6113f3 |
|
BLAKE2b-256 | d1d39ea456c97c8ca93329d9d4d28863b5c6a0205f969d34e1c1f9ab737a9111 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f9c3c74ed635adc72239ea5820cbb91ef4c3426a2a320892e42a199e4a294c7 |
|
MD5 | c9d18e9ade4dad39de0ffa6aa7b1f52b |
|
BLAKE2b-256 | 3c7c9ef6a10087b0630b85717a98830b7b30fa05797357422d90286a098cfa33 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp310-cp310-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8db8c47c141b7d7c429d6890a32adfad9482ff1893716cb5d33639f773b2d9b0 |
|
MD5 | 1de2783e6504c5d2dc46796a2797e1d1 |
|
BLAKE2b-256 | 18d96089eb9df07941d8336a11031bfbcbe896d9cd2c9888fee0cc511924347c |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0179c6bce2bdca680c0c0cdb5eefaef586eedf665c50608ec03d62cbc0a6832c |
|
MD5 | 9d5f28ee176a8e7eed71083992666e8a |
|
BLAKE2b-256 | 9f77a242a47f8216dbd6677e394c7103e42ddef42c364d8e49a8305c258ad65e |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f8c64964d4b43400b9a8cc7082a398b451a397ed524cc6ac3f3b6b615098f09 |
|
MD5 | 7938e99d2b76921691ddd5a90766fe3c |
|
BLAKE2b-256 | 85b3e512c071904edefeca9f63125a36e44117c3481bc2c6234ce7c419a4dc66 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp39-cp39-macosx_12_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 611736f35b2e42966f304eedb543e1815e9e0598a0c81c535071cc0187c87793 |
|
MD5 | c7baf2f5b435e4152a4e22cea15a234a |
|
BLAKE2b-256 | 185dab785beae4328206232d8eadb8018b5d6a2767e4bc1588475a5c82a5432f |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb671a847097d13519faec8920634612f72a1ac19d60d708e5ca0d5b226e99ce |
|
MD5 | 737ec81b5623f0c5d3c795b3bed48f47 |
|
BLAKE2b-256 | 833f5183ba1cdb2e47aa80ccf9d62cb5c1ae01d9ab03d5be92a43e8b9916a717 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 854ed4613059a30379247370d0530e4f6af5ba256ad581306d293dddb7f50beb |
|
MD5 | becd12ecc5ba4aa110a2f30338286026 |
|
BLAKE2b-256 | 65c1f8b0a70b5708c49a785959380d72781be6ae18e36f76b56bca8dbe9c77fe |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66924ac391f0caac9a3dc7020b222b89127a9a355e4aad335f8bf7cd99564180 |
|
MD5 | b69e3720c89784c70b7487b699ea619a |
|
BLAKE2b-256 | 6ee4fa27c45b9357d76202e40b5c2675b3bd143253311b80db04967d788da71a |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f74705bf39b119e3b433b98efa50e2678c6853c92403e2854317e1fa48462523 |
|
MD5 | 6a6edbcd0466154480cfdfeb86541243 |
|
BLAKE2b-256 | d05a822e5c4c2bfd5f070beed881a595d75088e0933be516edb8fc99f3c6a360 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a55aa54b83ac22b517f7a27b0b381b7f87368851779baabfe55ca3dead14d51c |
|
MD5 | 575b0fa5cb117019a9e1104a0f3e1cab |
|
BLAKE2b-256 | 1c92fbb553d76b883ec408a02008c2ba2b74e1a6f43a623484ad51c151391ee5 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e1242399b35e8a39e2132631aaee3927bdb9065f444c37345e57b7da86b0e1b |
|
MD5 | cde82ebd3e03d4994618e51875322f24 |
|
BLAKE2b-256 | 6f58e4090dea894bc4b7bef41cf852db0a86e7d0a7b8b34e1d29c3c98334e979 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 065b3d1cd931e00544477b78ab52029cf7064b6a8061bd29b4ce2a063b094d3f |
|
MD5 | 87006615eea49b7451edfd59178f65a8 |
|
BLAKE2b-256 | 737a255a15911159b02b455576c1da72fb78d1473999709c413162dcf2d304eb |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ec6701cf19ed80bdfdbcec09c95ed14908a21cbf24b0122a90ba484cf5fac74 |
|
MD5 | b4947de243b0a99e5bb5ade307d65508 |
|
BLAKE2b-256 | d87968f9ff7485da45de7881c8dfab7db6c18a9fd3bf2484b84470c2e24fabc8 |
Hashes for waifu2x_ncnn_py-1.1.0.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25e890ee0b7e5b8094684402592cdc4d91b571001acfc706368ef61858173f06 |
|
MD5 | b2c8faf8dcd685182346d524f4479e4e |
|
BLAKE2b-256 | 341e0242073bf7bce4bb912aca932ab04831b927677f0a4ad9639051e297f922 |