Skip to main content

No project description provided

Project description

span-ncnn-py

Custom models:

PyPI version test_pip Release PyPI - Python Version

Real-ESRGAN aims at developing Practical Algorithms for General Image/Video Restoration. We extend the powerful ESRGAN to a practical restoration application (namely, Real-ESRGAN), which is trained with pure synthetic data. This wrapper provides an easy-to-use interface for running the pre-trained Real-ESRGAN 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

Python >= 3.6 (>= 3.9 in MacOS arm)

To use this package, simply install it via pip:

pip install span-ncnn-py

For Linux user:

apt install -y libomp5 libvulkan-dev

Then, import the span class from the package:

from span_ncnn_py import span

To initialize the model:

span = Span(gpuid: int = 0, tta_mode: bool = False, tilesize: int = 0, model: int = 0)
# model can be 0, 1, 2, 3, 4, 5, 6; 0 for default
# 0: {"param": "spanx2_ch48.param", "bin": "spanx2_ch48.bin", "scale": 2},
# 1: {"param": "spanx2_ch52.param", "bin": "spanx2_ch52.bin", "scale": 2},
# 2: {"param": "spanx4_ch48.param", "bin": "spanx4_ch48.bin", "scale": 4},
# 3: {"param": "spanx4_ch52.param", "bin": "spanx4_ch52.bin", "scale": 4},
# 4: {"param": "2xHFA2kSPAN_27k.param", "bin": "2xHFA2kSPAN_27k.bin", "scale": 2},
# 5: {"param": "4xSPANkendata.param", "bin": "4xSPANkendata.bin", "scale": 4},
# 6: {"param": "ClearReality4x.param", "bin": "ClearReality4x.bin", "scale": 4}

Here, gpuid specifies the GPU device to use, tta_mode enables test-time augmentation, tilesize specifies the tile size for processing (0 or >= 32), and model specifies the num 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

span = span(gpuid=0)
with Image.open("input.jpg") as image:
    image = span.process_pil(image)
    image.save("output.jpg", quality=95)

opencv-python

import cv2

span = span(gpuid=0)
image = cv2.imdecode(np.fromfile("input.jpg", dtype=np.uint8), cv2.IMREAD_COLOR)
image = span.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)
realesrgan = Realesrgan(gpuid=0)
while True:
    raw_image = pipe_out.stdout.read(src_width * src_height * 3)
    if not raw_image:
        break
    raw_image = realesrgan.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:

xinntao/Real-ESRGAN-ncnn-vulkan - This project was the main inspiration for our work. It provided the core implementation of the Real-ESRGAN algorithm using the ncnn and Vulkan libraries.

Real-ESRGAN - Real-ESRGAN is an AI super resolution model, aims at developing Practical Algorithms for General Image/Video Restoration.

media2x/realsr-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 Distribution

span_ncnn_py-1.0.0.tar.gz (10.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

span_ncnn_py-1.0.0-py3-none-any.whl (9.0 MB view details)

Uploaded Python 3

File details

Details for the file span_ncnn_py-1.0.0.tar.gz.

File metadata

  • Download URL: span_ncnn_py-1.0.0.tar.gz
  • Upload date:
  • Size: 10.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for span_ncnn_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 04d9d4ccd59364b86cb8736e2546ba4a69700eee5de989b1902f1aa31a3812ce
MD5 e84532f1317a2542c1e0d2099d4ded02
BLAKE2b-256 6085608895368fda6550e2595946782ad0a9a5118e735b32666cfa7bbb6fac45

See more details on using hashes here.

File details

Details for the file span_ncnn_py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: span_ncnn_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for span_ncnn_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8ee2ffab468ed7b315bbcc323c906c00c038f950a16ab4daccad7a16352a0cb
MD5 ebeb1834756d298d2c7a9e5f11525064
BLAKE2b-256 d599f210fa291cc26cce849cfc2ed7336c2f20503b963c7b209241885c01116a

See more details on using hashes here.

Supported by

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