2022-07-21 10:12:10 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import os.path as osp
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
import cv2
|
|
|
|
|
|
|
|
|
|
from modelscope.outputs import OutputKeys
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.pipelines.base import Pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-05-22 10:53:18 +08:00
|
|
|
class ImageSuperResolutionTest(unittest.TestCase):
|
2022-07-21 10:12:10 +08:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.model_id = 'damo/cv_rrdb_image-super-resolution'
|
|
|
|
|
self.img = 'data/test/images/dogs.jpg'
|
2022-09-08 14:08:51 +08:00
|
|
|
self.task = Tasks.image_super_resolution
|
2022-07-21 10:12:10 +08:00
|
|
|
|
|
|
|
|
def pipeline_inference(self, pipeline: Pipeline, img: str):
|
|
|
|
|
result = pipeline(img)
|
|
|
|
|
if result is not None:
|
|
|
|
|
cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
|
|
|
|
|
print(f'Output written to {osp.abspath("result.png")}')
|
|
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-07-21 10:12:10 +08:00
|
|
|
def test_run_modelhub(self):
|
|
|
|
|
super_resolution = pipeline(
|
2022-07-21 18:17:25 +08:00
|
|
|
Tasks.image_super_resolution, model=self.model_id)
|
2022-07-21 10:12:10 +08:00
|
|
|
|
|
|
|
|
self.pipeline_inference(super_resolution, self.img)
|
|
|
|
|
|
2022-07-21 18:17:25 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_modelhub_default_model(self):
|
|
|
|
|
super_resolution = pipeline(Tasks.image_super_resolution)
|
|
|
|
|
self.pipeline_inference(super_resolution, self.img)
|
|
|
|
|
|
2022-07-21 10:12:10 +08:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|