Commit 38e8253b authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): add new benchmark

parent 083a37cd
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
import random

from benchmark import BaseBenchmark, create_plot_cli
from imgutils.restore.scunet import SCUNetModelTyping, restore_with_scunet


class SCUNetBenchmark(BaseBenchmark):
    def __init__(self, model: SCUNetModelTyping):
        BaseBenchmark.__init__(self)
        self.model = model

    def load(self):
        from imgutils.restore.scunet import _open_scunet_model
        _open_scunet_model(self.model)

    def unload(self):
        from imgutils.restore.scunet import _open_scunet_model
        _open_scunet_model.cache_clear()

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


if __name__ == '__main__':
    create_plot_cli(
        [
            ('SCUNet-GAN', SCUNetBenchmark('GAN')),
            ('SCUNet-PSNR', SCUNetBenchmark('PSNR')),
        ],
        title='Benchmark for SCUNet Models',
        run_times=5,
        try_times=10,
    )()
+17 −0
Original line number Diff line number Diff line
"""
Overview:
    Restore the images using `NafNet <https://github.com/megvii-research/NAFNet>`_.

    .. image:: nafnet_demo.plot.py.svg
        :align: center

    This is an overall benchmark of all the NafNet models:

    .. image:: nafnet_benchmark.plot.py.svg
        :align: center

    .. warning::
        Currently, we've identified a significant issue with NafNet when images contain gaussian noise.
        To ensure your code functions correctly, please ensure the credibility of
        your image source or preprocess them using SCUNet.
"""
from functools import lru_cache
from typing import Literal

+13 −0
Original line number Diff line number Diff line
"""
Overview:
    Restore the images using `SCUNet <https://github.com/cszn/SCUNet>`_.

    .. image:: scunet_demo.plot.py.svg
        :align: center

    This is an overall benchmark of all the SCUNet models:

    .. image:: scunet_benchmark.plot.py.svg
        :align: center

"""
from functools import lru_cache
from typing import Literal