Unverified Commit f72c4f4f authored by narugo1992's avatar narugo1992 Committed by GitHub
Browse files

Merge pull request #88 from deepghs/dev/cdc

dev(narugo): add support for cdc upscaler
parents 5de99ab1 09a2b037
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
imgutils.upscale.cdc
====================================

.. currentmodule:: imgutils.upscale.cdc

.. automodule:: imgutils.upscale.cdc


upscale_with_cdc
---------------------------

.. autofunction:: upscale_with_cdc


+44 −0
Original line number Diff line number Diff line
import os.path
import random

from huggingface_hub import HfFileSystem

from benchmark import BaseBenchmark, create_plot_cli
from imgutils.upscale.cdc import upscale_with_cdc

hf_fs = HfFileSystem()
repository = 'deepghs/cdc_anime_onnx'
_CDC_MODELS = [
    os.path.splitext(os.path.relpath(file, repository))[0]
    for file in hf_fs.glob(f'{repository}/*.onnx')
]


class CDCUpscalerBenchmark(BaseBenchmark):
    def __init__(self, model: str):
        BaseBenchmark.__init__(self)
        self.model = model

    def load(self):
        from imgutils.upscale.cdc import _open_cdc_upscaler_model
        _open_cdc_upscaler_model(self.model)

    def unload(self):
        from imgutils.upscale.cdc import _open_cdc_upscaler_model
        _open_cdc_upscaler_model.cache_clear()

    def run(self):
        image_file = random.choice(self.all_images)
        _ = upscale_with_cdc(image_file, model=self.model)


if __name__ == '__main__':
    create_plot_cli(
        [
            (model, CDCUpscalerBenchmark(model))
            for model in _CDC_MODELS
        ],
        title='Benchmark for CDCUpscaler Models',
        run_times=3,
        try_times=3,
    )()
+2154 −0

File added.

Preview size limit exceeded, changes collapsed.

+36 −0
Original line number Diff line number Diff line
import os

from huggingface_hub import HfFileSystem

from imgutils.upscale import upscale_with_cdc
from imgutils.upscale.cdc import _open_cdc_upscaler_model
from plot import image_plot

hf_fs = HfFileSystem()
repository = 'deepghs/cdc_anime_onnx'
_CDC_MODELS = [
    os.path.splitext(os.path.relpath(file, repository))[0]
    for file in hf_fs.glob(f'{repository}/*.onnx')
]

if __name__ == '__main__':
    demo_images = [
        ('sample/original.png', 'Small Logo'),
        ('sample/skadi.jpg', 'Illustration'),
        ('sample/hutao.png', 'Large Illustration'),
        # ('sample/xx.jpg', 'Illustration #2'),
        ('sample/rgba_restore.png', 'RGBA Artwork'),
    ]

    items = []
    for file, title in demo_images:
        items.append((file, title))
        for model in _CDC_MODELS:
            _, scale = _open_cdc_upscaler_model(model)
            items.append((upscale_with_cdc(file, model=model), f'{title}\n({scale}X By {model})'))

    image_plot(
        *items,
        columns=len(_CDC_MODELS) + 1,
        figsize=(4 * (len(_CDC_MODELS) + 1), 3.5 * len(demo_images)),
    )
+1593 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading