Skip to main content

No project description provided

Project description

realesrgan-ncnn-py

Python Binding for realesrgan-ncnn-py with PyBind11 PyPI version Release

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:
Linux (GCC) CI-Linux-x64-GCC :white_check_mark:
Windows CI-Windows-x64-MSVC :white_check_mark:
MacOS CI-MacOS-Universal-Clang :white_check_mark:
MacOS (ARM) CI-MacOS-Universal-Clang :white_check_mark:

Usage

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

To use this package, simply install it via pip:

pip install realesrgan-ncnn-py

For Linux user:

apt install -y libomp5 libvulkan-dev

Then, import the Realesrgan class from the package:

from realesrgan_ncnn_py import Realesrgan

To initialize the model:

realesrgan = Realesrgan(gpuid: int = 0, tta_mode: bool = False, tilesize: int = 0, model: int = 0, **_kwargs)
# model can be -1, 0, 1, 2, 3, 4; 0 for default, -1 for custom load
# 0: {"param": "realesr-animevideov3-x2.param", "bin": "realesr-animevideov3-x2.bin", "scale": 2},
# 1: {"param": "realesr-animevideov3-x3.param", "bin": "realesr-animevideov3-x3.bin", "scale": 3},
# 2: {"param": "realesr-animevideov3-x4.param", "bin": "realesr-animevideov3-x4.bin", "scale": 4},
# 3: {"param": "realesrgan-x4plus-anime.param", "bin": "realesrgan-x4plus-anime.bin", "scale": 4},
# 4: {"param": "realesrgan-x4plus.param", "bin": "realesrgan-x4plus.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
realesrgan = Realesrgan(gpuid=0)
with Image.open("input.jpg") as image:
    image = realesrgan.process_pil(image)
    image.save("output.jpg", quality=95)

opencv-python

import cv2
realesrgan = Realesrgan(gpuid=0)
image = cv2.imdecode(np.fromfile("input.jpg", dtype=np.uint8), cv2.IMREAD_COLOR)
image = realesrgan.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 Distributions

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

Built Distributions

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

realesrgan_ncnn_py-1.2.0.0-cp311-cp311-win_amd64.whl (43.9 MB view details)

Uploaded CPython 3.11Windows x86-64

realesrgan_ncnn_py-1.2.0.0-cp311-cp311-manylinux1_x86_64.whl (45.7 MB view details)

Uploaded CPython 3.11

realesrgan_ncnn_py-1.2.0.0-cp311-cp311-macosx_12_0_universal2.whl (51.2 MB view details)

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

realesrgan_ncnn_py-1.2.0.0-cp310-cp310-win_amd64.whl (43.9 MB view details)

Uploaded CPython 3.10Windows x86-64

realesrgan_ncnn_py-1.2.0.0-cp310-cp310-manylinux1_x86_64.whl (45.7 MB view details)

Uploaded CPython 3.10

realesrgan_ncnn_py-1.2.0.0-cp310-cp310-macosx_12_0_universal2.whl (51.2 MB view details)

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

realesrgan_ncnn_py-1.2.0.0-cp39-cp39-win_amd64.whl (43.9 MB view details)

Uploaded CPython 3.9Windows x86-64

realesrgan_ncnn_py-1.2.0.0-cp39-cp39-manylinux1_x86_64.whl (45.7 MB view details)

Uploaded CPython 3.9

realesrgan_ncnn_py-1.2.0.0-cp39-cp39-macosx_12_0_universal2.whl (51.2 MB view details)

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

realesrgan_ncnn_py-1.2.0.0-cp38-cp38-win_amd64.whl (43.9 MB view details)

Uploaded CPython 3.8Windows x86-64

realesrgan_ncnn_py-1.2.0.0-cp38-cp38-manylinux1_x86_64.whl (45.7 MB view details)

Uploaded CPython 3.8

realesrgan_ncnn_py-1.2.0.0-cp38-cp38-macosx_10_15_x86_64.whl (51.2 MB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-win_amd64.whl (43.9 MB view details)

Uploaded CPython 3.7mWindows x86-64

realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-manylinux1_x86_64.whl (45.7 MB view details)

Uploaded CPython 3.7m

realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-macosx_10_15_x86_64.whl (51.2 MB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-win_amd64.whl (43.9 MB view details)

Uploaded CPython 3.6mWindows x86-64

realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-manylinux1_x86_64.whl (45.7 MB view details)

Uploaded CPython 3.6m

realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-macosx_10_15_x86_64.whl (51.2 MB view details)

Uploaded CPython 3.6mmacOS 10.15+ x86-64

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 49bfed2c9feda3498ba56c5442b313e3903108bffb93057aabfd6081c5e7e12a
MD5 d72a58750c923c1cbe200584455b3272
BLAKE2b-256 eb87b66006d289a1764d20a343b9bb8f4d7d9793813120b3f5a1f1c719392b99

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp311-cp311-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 923eae9aa1f20d9d21903cccdc71a86710d7237f5058eb66c98b4c73603831fd
MD5 64e150595dd7af6d16f4f94353d442ae
BLAKE2b-256 42a4d593c884f7b75aa4f90c3f6644323dc8719dc783a29c8c04e75c992e7c79

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp311-cp311-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp311-cp311-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 63e00bd8fb2f17ebf698ad3218f273a13ac540a0a6d4a621128d94cd5f303c5c
MD5 f30d94e0d59eaf9e4b1036d1980f2a4f
BLAKE2b-256 216244d1d91ce0be1daa1f4aec6f64075f290ac35c0ebe98c5d14c8b601be848

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 53fda80c34ceba817a1ffade3714ba87e585246f921db78ab91db3c5b72ff2fc
MD5 7e45b49f9b4dfe3eb97c64bc610cac25
BLAKE2b-256 77e8c6fc3297f27105932471a41f3b98aba1ba25776d893c89a29f01d7b8c6ed

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 64a789133210d6d10da79d57ff4aaa6a6482ba93c1f1f16bbbdde410b5ea9c2a
MD5 04bac52e1c68eefa7897fed39fcfb841
BLAKE2b-256 d36068c7b812351326b103eb5aa03d8dc825ddad643a0d13d08b8a9bb8f150b0

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp310-cp310-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp310-cp310-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 dcbb31b1057ddc940124da5e27f8030f353c9258b158c2b71573c17037974d7f
MD5 1b389efd480c11489702e81ee878c5ba
BLAKE2b-256 e6583e20542e429442619905899a3a07c2470c1e8562ba4996824f6b4867c93a

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e03b9d7dd51c3d7f8b3e1d555cc06de8b64844b6aec6ab8a54151307244e72e8
MD5 e502e1404e4e719e3f54f9214a255955
BLAKE2b-256 66449615242625b90f5ca4a2728df2903a67d15744ca778e4abdfe1a1a973365

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp39-cp39-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e487d4ef189f8054714cd3d0e5fcb96c176a8395ea60b2c5a17811166cf40025
MD5 f710fe57bfc82b06b2327882ff1bfd9a
BLAKE2b-256 837b59f2123dad35d89e8913409943fc3c198f015375adabf74e8d8c09bcce67

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp39-cp39-macosx_12_0_universal2.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp39-cp39-macosx_12_0_universal2.whl
Algorithm Hash digest
SHA256 59a4146adcee19dc71c3fc0d202d2093b6295f73642186e1c6d1e0fe52e436a2
MD5 e5d5a2b6f023ba41c7af188ca1f0f339
BLAKE2b-256 4d0b086d24acb64a0721fdab3e62a431b569dd73ced4a35a6d35d20dca8f880b

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b47ca5444391f9e2f66d85ac51c31c803f1c6ead7e3e59676d320e39456ed245
MD5 52687fb64647b5f255d76784e1b35e92
BLAKE2b-256 cfab0ad1b11e323b403a5c376877f11e7f643ebc15eaa01867c67620fce8e216

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 aea5d96085a317d9f3b2cb58f16209de49ad34ad510f541d467993f55adf5d2a
MD5 fec099cdd3011559fd00450f1d2b7d97
BLAKE2b-256 206f9a7069522dfc3ed4df084b561658c863058c03d8fdf791007406bece6e65

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4e3be33119ea1eb51693981362ddad00ad91885aac2bbe70203273492947ab56
MD5 662f4cf2f006f459a5158871ac589c16
BLAKE2b-256 84ac7f7ee6e6319df988bcbf491d4cd7c8e3184dd754ae48329ca16db2126108

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 1da16bd2f8fe0ad26c146b2ec8b833087844b73e8630008bc02015dff9a69ebb
MD5 7404a2f8e3224d1e607b168cf5ff60ff
BLAKE2b-256 3cef9b09ee40deb28b7183fa9ce12b020d8bdca724aac5f2ed4b736fc26a455b

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cb760970919244f3d69e30e1e10e9204c5a3d0b87fc36e4be00f559c76ccb56d
MD5 c25d82c372cb0d59857d56cdbf509a68
BLAKE2b-256 65a7809a182133f6e47bced2cc4a945f2f8c521e923a1e2f492592581b280da9

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 29013d5b3039e3545b1fd7f904a51b07f139fed5f2aceb29118cae8721aeb34c
MD5 8045772b0e0bc8a60f286befd39b05dd
BLAKE2b-256 a365c8bac40f1d4b1f7e89f45e81db4d0c4cb70e64301cda8d208fc2c325f85e

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f02a11fd35b8bfc7c3414bdb26dedf2e2a9415d9e132f5ce9a36107d3e8534ca
MD5 d2e4ebf8dbd656319c79d6fa50540e55
BLAKE2b-256 6be86d8a3e3ab7e7d32c16c6a55a096ea1065be62ccdde22bb7430d22e6ef11a

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a8d1d5be5cc0ccd930938a27943157c5de0011190c2f1272c25743f9b4255df6
MD5 5b8709b2a0f76db83b113c182c0f0a11
BLAKE2b-256 9b72441ebb8c1cb5744631381aff4fbedee70446a5a42e4004870e2023fdb044

See more details on using hashes here.

File details

Details for the file realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for realesrgan_ncnn_py-1.2.0.0-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 96b937488f3be69d4a72550d0707fbbbf1fe2f00f794b4141d3c80cbabb10e45
MD5 d133d1238e670879ebb107d241f211e7
BLAKE2b-256 d8d3cdaf2c8c53fc52c1cea8de1958b84ced9324686a201bcb371f6fd33391be

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