Skip to main content

No project description provided

Project description

upscale-ncnn-py

Custom SPAN models:

PyPI version test_pip Release PyPI - Python Version

Span go brrr for upscaling images.

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 upscale-ncnn-py

Then, import the upscale class from the package:

from upscale_ncnn_py import UPSCALE

To initialize the model:

upscale = UPSCALE(gpuid: int = 0, tta_mode: bool = False, tilesize: int = 0, model: int = 0)
# model can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19; 0 for default
#span
0: {"param": "spanx2_ch48.param", "bin": "spanx2_ch48.bin", "scale": 2, "folder": "models/SPAN"},
1: {"param": "spanx2_ch52.param", "bin": "spanx2_ch52.bin", "scale": 2, "folder": "models/SPAN"},
2: {"param": "spanx4_ch48.param", "bin": "spanx4_ch48.bin", "scale": 4, "folder": "models/SPAN"},
3: {"param": "spanx4_ch52.param", "bin": "spanx4_ch52.bin", "scale": 4, "folder": "models/SPAN"},
#custom span
4: {"param": "2x_ModernSpanimationV1.param", "bin": "2x_ModernSpanimationV1.bin", "scale": 2, "folder": "models/SPAN"},
5: {"param": "4xSPANkendata.param", "bin": "4xSPANkendata.bin", "scale": 4, "folder": "models/SPAN"},
6: {"param": "ClearReality4x.param", "bin": "ClearReality4x.bin", "scale": 4, "folder": "models/SPAN"},

#esrgan
7: {"param": "realesr-animevideov3-x2.param", "bin": "realesr-animevideov3-x2.bin", "scale": 2, "folder": "models/ESRGAN"},
8: {"param": "realesr-animevideov3-x3.param", "bin": "realesr-animevideov3-x3.bin", "scale": 3, "folder": "models/ESRGAN"},
9: {"param": "realesr-animevideov3-x4.param", "bin": "realesr-animevideov3-x4.bin", "scale": 4, "folder": "models/ESRGAN"},
10: {"param": "realesrgan-x4plus-x4.param", "bin": "realesrgan-x4plus.bin", "scale": 4, "folder": "models/ESRGAN"},
11: {"param": "realesrgan-x4plus-anime.param", "bin": "realesrgan-x4plus-anime.bin", "scale": 4, "folder": "models/ESRGAN"},

#cugan-se models 
12: {"param": "up2x-conservative.param", "bin": "up2x-conservative.bin", "scale": 2, "folder": "models/CUGAN/models-se"},
13: {"param": "up2x-no-denoise.param", "bin": "up2x-no-denoise.bin", "scale": 2, "folder": "models/CUGAN/models-se"},
14: {"param": "up2x-denoise1x.param", "bin": "up2x-denoise1x.bin", "scale": 2, "folder": "models/CUGAN/models-se"},
15: {"param": "up2x-denoise2x.param", "bin": "up2x-denoise2x.bin", "scale": 2, "folder": "models/CUGAN/models-se"},
16: {"param": "up2x-denoise3x.param", "bin": "up2x-denoise3x.bin", "scale": 2, "folder": "models/CUGAN/models-se"},

17: {"param": "up3x-conservative.param", "bin": "up3x-conservative.bin", "scale": 3, "folder": "models/CUGAN/models-se"},
18: {"param": "up3x-no-denoise.param", "bin": "up3x-no-denoise.bin", "scale": 3, "folder": "models/CUGAN/models-se"},
19: {"param": "up3x-denoise3x.param", "bin": "up3x-denoise3x.bin", "scale": 3, "folder": "models/CUGAN/models-se"},

20: {"param": "up4x-conservative.param", "bin": "up4x-conservative.bin", "scale": 4, "folder": "models/CUGAN/models-se"},
21: {"param": "up4x-no-denoise.param", "bin": "up4x-no-denoise.bin", "scale": 4, "folder": "models/CUGAN/models-se"},
22: {"param": "up4x-denoise3x.param", "bin": "up3x-denoise3x.bin", "scale": 4, "folder": "models/CUGAN/models-se"},

#cugan-pro models
23: {"param": "up2x-denoise3x.param", "bin": "up2x-denoise3x.bin", "scale": 2, "folder": "models/CUGAN/models-pro"},
24: {"param": "up2x-conservative.param", "bin": "up2x-conservative.bin", "scale": 2, "folder": "models/CUGAN/models-pro"},
25: {"param": "up2x-no-denoise.param", "bin": "up2x-no-denoise.bin", "scale": 2, "folder": "models/CUGAN/models-pro"},

26: {"param": "up3x-denoise3x", "bin": "denoise3x-up3x", "scale": 3, "folder": "models/CUGAN/models-pro"},
27: {"param": "up3x-conservative", "bin": "up3x-conservative.bin", "scale": 3, "folder": "models/CUGAN/models-pro"},
28: {"param": "up3x-no-denoise.param", "bin": "up3x-no-denoise.bin", "scale": 3, "folder": "models/CUGAN/models-pro"},

#shufflecugan
29: {"param": "sudo_shuffle_cugan-x2.param", "bin": "sudo_shuffle_cugan-x2.bin", "scale": 2, "folder": "models/SHUFFLECUGAN"},

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

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

opencv-python

import cv2

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

upscale_ncnn_py-1.2.0-cp313-none-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.13Windows x86-64

upscale_ncnn_py-1.2.0-cp313-none-manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.13

upscale_ncnn_py-1.2.0-cp313-none-manylinux1_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.13

upscale_ncnn_py-1.2.0-cp312-none-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

upscale_ncnn_py-1.2.0-cp312-none-manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.12

upscale_ncnn_py-1.2.0-cp312-none-manylinux1_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.12

upscale_ncnn_py-1.2.0-cp312-none-macosx_11_0_universal2.whl (10.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ universal2 (ARM64, x86-64)

upscale_ncnn_py-1.2.0-cp311-none-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86-64

upscale_ncnn_py-1.2.0-cp311-none-manylinux1_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.11

upscale_ncnn_py-1.2.0-cp311-none-macosx_11_0_universal2.whl (10.1 MB view details)

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

upscale_ncnn_py-1.2.0-cp310-none-manylinux1_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.10

File details

Details for the file upscale_ncnn_py-1.2.0-cp313-none-win_amd64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp313-none-win_amd64.whl
Algorithm Hash digest
SHA256 27bc202edc3cb0403f5daff26c4fbc9e83ac3d4e1101b926adc2353ba101f857
MD5 fd8570870e698d7f2dfbf2b9ccfcc430
BLAKE2b-256 21d05f74ebdce0efbe06b8814f6fd71cf1b5c81d1e5c1ccacf38de7d0b31bdf1

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp313-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp313-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 95ecd7a3d5e4269da0e7737dcbe6a38ef3cced635a60cc3cc393c3c85679e816
MD5 bf4e4f20e9a970d523aec25068e2a01d
BLAKE2b-256 1e88836376478f12eef52cca3aab683a0c978654af9e4d6a50376b6a7c558b8c

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp313-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp313-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3bfc52a1589cde8c4d970ee0e3bd6d3af7843a8abbe3e86e429c1f576c28f696
MD5 2fef4a50e70fdb8793ca041452d524cf
BLAKE2b-256 dda52977bfa1aacc0dd628dec71c1ecb93f2e66d0c489ae1b39fcf7ffcfb6478

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 09f8769fd08f924e9f80e9ed992ad7feca280732228d4d706d7b87a0686da4e0
MD5 f1485793591c4556bcef956a8a208fc3
BLAKE2b-256 974e2bab59b1d5591a37b3da2b87d8cae035c8c0c410a4f94ea83c19849ceacb

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp312-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp312-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a2db6c86381305ce717c2c1e4fe7af83121e5f4e7cf6191cc7f79f6318bb7d46
MD5 efee66bfd5c6d5a99178adfafcd426dd
BLAKE2b-256 065d5870af25ef9693661ec8eeb182ea9ddd49e6fb78c0dbb1c709b7f3d4f5ac

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp312-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp312-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f8a6b161aba8d414e3a0bd0f8e9cba91045bb3e5de806f517df4d25e2627eb58
MD5 c78dc1b234bb3fd40327547d35b91d8e
BLAKE2b-256 e03b44ebc02f1e659ab9ec388db46e31f4776cdf9bf90c0d5e8729289dd5403f

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp312-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp312-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 f04b6dd293ee0c70cd2211007bedb6dfb198d62200434338962b5ed1eb124734
MD5 c6834db5a54df2fa3ba0ea209d549f3a
BLAKE2b-256 f2f977bcbf67e0d878896f2e43c11966a7ffb815f42df8df3ea0ecf9335d47c5

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 feac4e08fe5d4b6255a844b6cc014b02994eeb7bf7d55165fd5d9e140f3676df
MD5 b96d79ae0173df7dcd5ac4a063ed83c8
BLAKE2b-256 e87812eab86110d8a6b9c02b14ac6e16954055d04cb53fce03f29a697bf24d27

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp311-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp311-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cb5c10ec43e6b9bb5edf116ea71dc2203b36ef1d3c094dbb0e603598d0d6d45d
MD5 bf0ab6f91706c844a14ebbe43e872572
BLAKE2b-256 254d51483deba7dc2f2a4959ac48e349195f00e98e5e0f35fdf4a42d0448ea46

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp311-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp311-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 c5ba953f4436bd0ec830c8eb6f42fbe417cff892b1878ece711af921dd60e8cc
MD5 25e37fcb454418756595f6a2f973309a
BLAKE2b-256 edb0127b4787a5bd950871a97abdb730f07be673d055bd45bcdfe4b5ab1b84f1

See more details on using hashes here.

File details

Details for the file upscale_ncnn_py-1.2.0-cp310-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for upscale_ncnn_py-1.2.0-cp310-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 22ed11174937865ea606005e5039a9f06cffe8de000c5191f933c1e24e1b0ce5
MD5 d44aaf7e9f6fb8312a26d2edc7ce19bc
BLAKE2b-256 bd20143d14806e154fe19c210d26bfb3603c56464bd87cbd5dfbd85a8d269a58

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