A Python FFI of nihui/realcugan-ncnn-vulkan achieved with SWIG
Project description
realcugan ncnn Vulkan Python
Introduction
A Python FFI of nihui/realcugan-ncnn-vulkan achieved with SWIG.
realcugan-ncnn-vulkan is nihui's ncnn implementation of realcugan converter. Runs fast on Intel / AMD / Nvidia with Vulkan API.
This project only wrapped the original RealCUGAN 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.
- However, for Linux (Like Ubuntu 18.04) with an older GLIBC (version < 2.29), you may try to use the ubuntu-1804 release or just compile it on your own.
- Windows release is not working for all python version. The version of Windows build is for python 3.9. This is a known issue: ImportError: DLL load failed while importing _rife_ncnn_vulkan_wrapper: The specified module could not be found.
Update: it has been uploaded to PyPI, and you can install it with pip now.
Installation
pip install realcugan-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
- 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
- Build with CMake
git clone https://github.com/ArchieMeng/realcugan-ncnn-vulkan-python.git
cd realcugan-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
- install dependencies: cmake, vulkan sdk, swig and python-dev
- download vulkan sdk from https://vulkan.lunarg.com/sdk/home
- If you have homebrew installed, run the command below to get SWIG
brew install swig
- I guess python dev is out-of-box in Mac. If not, google it.
- 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/realcugan-ncnn-vulkan-python.git
cd realcugan-ncnn-vulkan-python
git submodule update --init --recursive
cd src
cmake -B build .
cd build
make
Usages
Example program
from PIL import Image
from realcugan_ncnn_vulkan import RealCUGAN
with Image.open("input.png") as image:
realcugan = RealCUGAN(gpuid=0, scale=2, noise=3)
image = realcugan.process(image)
image.save("output.png")
Docs
Known issues
- Module finalization will crash for nvidia dedicated graphics card(s) on Linux. (The image processing still works.)
- Not yet tested for Mac OS. I guess it should work.
Original realcugan Project
- https://github.com/bilibili/ailab/tree/main/Real-CUGAN
- https://github.com/nihui/realcugan-ncnn-vulkan
Other Open-Source Code Used
- https://github.com/Tencent/ncnn for fast neural network inference on ALL PLATFORMS
- https://github.com/webmproject/libwebp for encoding and decoding Webp images on ALL PLATFORMS
- https://github.com/nothings/stb for decoding and encoding image on Linux / MacOS
- https://github.com/tronkko/dirent for listing files in directory on Windows
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 Distribution
Hashes for realcugan-ncnn-vulkan-python-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f72764ffe0a0c53b13cdbe1ae328ff9b0eb5582b9d5d15a0ca0c0ac254d17410 |
|
MD5 | bc8955da3f5cc733e2ce01e4b066ffcd |
|
BLAKE2b-256 | 747c18c553e349acfbe23c095b815e609e1dd891d2d28afdfc80e3f6b9487279 |