Skip to main content

A Python FFI of nihui/waifu2x-ncnn-vulkan achieved with SWIG

Project description

waifu2x ncnn Vulkan Python

CI

Introduction

A Python FFI of nihui/waifu2x-ncnn-vulkan achieved with SWIG.

waifu2x-ncnn-vulkan is nihui's ncnn implementation of waifu2x converter. Runs fast on Intel / AMD / Nvidia with Vulkan API.

This project only wrapped the original Waifu2x class. As a result, functions other than the core upscaling and denoising such as multi-thread loading and saving are not available. Of course, the auto tilesize and prepadding settings are implements, so don't worry about them.

Download

linux x64, Windows x64 and MacOS x64 releases are available now. For other platforms, you may compile it on your own. The reason why MacOS ARM64 build is not available is that it needs ARM Python Dev Libs which I have no ideas on how to get it on Github's MacOS x64 VM. Moreover, I don't have a Mac.

Update: it has been uploaded to PyPI, and you can install it with pip now.

Installation

pip install waifu2x-ncnn-vulkan-python

Build

First, you have to install python, python development package (Python native development libs in Visual Studio), vulkan SDK and SWIG on your platform. And then, there are two ways to build it:

  • Use setuptools to build and install into python package directly. (Currently in developing)
  • Use CMake directly (The old way)

Use setuptools

python setup.py install

Use CMake

Linux

  1. install dependencies: cmake, vulkan sdk, swig and python-dev

Debian, Ubuntu and other Debian-like Distros

apt-get install cmake libvulkan-dev swig python3-dev

Arch Distros

pacman -S base-devel cmake vulkan-headers vulkan-icd-loader swig python
  1. Build with CMake
git clone https://github.com/ArchieMeng/waifu2x-ncnn-vulkan-python.git
cd waifu2x-ncnn-vulkan-python
git submodule update --init --recursive
cd src
cmake -B build .
cd build
make

Windows

I used Visual Studio 2019 and msvc v142 to build this project for Windows.

Install visual studio and open the project directory, and build. Job done.

The only problem on Windows is that, you cannot use CMake for Windows GUI to generate the Visual Studio solution file and build it. This will make the lib crash on loading.

One way is using Visual Studio to open the project as directory, and build it from Visual Studio. And another way is build it from powershell just like what is written in the release.yml

Mac OS X

  1. install dependencies: cmake, vulkan sdk, swig and python-dev
brew install swig
  • I guess python dev is out-of-box in Mac. If not, google it.
  1. Build with CMake
  • You can pass -DUSE_STATIC_MOLTENVK=ON option to avoid linking the vulkan loader library on MacOS
git clone https://github.com/ArchieMeng/waifu2x-ncnn-vulkan-python.git
cd waifu2x-ncnn-vulkan-python
git submodule update --init --recursive
cd src
cmake -B build .
cd build
make

Usages

Example program

from PIL import Image
from waifu2x_ncnn_vulkan import Waifu2x

with Image.open("input.png") as image:
  waifu2x = Waifu2x(gpuid=0, scale=2, noise=3)
  image = waifu2x.process(image)
  image.save("output.png")

Docs

Known issues

Original waifu2x Project

Other Open-Source Code Used

Project details


Download files

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

Source Distribution

waifu2x-ncnn-vulkan-python-1.0.2rc3.tar.gz (52.7 MB view details)

Uploaded Source

File details

Details for the file waifu2x-ncnn-vulkan-python-1.0.2rc3.tar.gz.

File metadata

  • Download URL: waifu2x-ncnn-vulkan-python-1.0.2rc3.tar.gz
  • Upload date:
  • Size: 52.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.4.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for waifu2x-ncnn-vulkan-python-1.0.2rc3.tar.gz
Algorithm Hash digest
SHA256 717a99077f267af4eca56b247c76d17d4b7b13e0f3cdf5561cb8557a2a4561a6
MD5 b32e7610d032f7b1d92bbf8a6b44141c
BLAKE2b-256 68a9bc25aac93f8264a703b401bcb7ce32122d35693430a238511fa3ef188f20

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