2022-08-16 09:15:53 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.outputs import OutputKeys
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
2022-09-08 14:08:51 +08:00
|
|
|
from modelscope.utils.demo_utils import DemoCompatibilityCheck
|
2022-08-16 09:15:53 +08:00
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2022-09-08 14:08:51 +08:00
|
|
|
class SalientDetectionTest(unittest.TestCase, DemoCompatibilityCheck):
|
|
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
2022-09-27 15:01:05 +08:00
|
|
|
self.task = Tasks.semantic_segmentation
|
2022-09-08 14:08:51 +08:00
|
|
|
self.model_id = 'damo/cv_u2net_salient-detection'
|
2022-08-16 09:15:53 +08:00
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_salient_detection(self):
|
|
|
|
|
input_location = 'data/test/images/image_salient_detection.jpg'
|
|
|
|
|
model_id = 'damo/cv_u2net_salient-detection'
|
2022-09-27 15:01:05 +08:00
|
|
|
salient_detect = pipeline(Tasks.semantic_segmentation, model=model_id)
|
2022-08-16 09:15:53 +08:00
|
|
|
result = salient_detect(input_location)
|
|
|
|
|
import cv2
|
|
|
|
|
cv2.imwrite(input_location + '_salient.jpg', result[OutputKeys.MASKS])
|
|
|
|
|
|
2022-09-09 14:56:15 +08:00
|
|
|
@unittest.skip('demo compatibility test is only enabled on a needed-basis')
|
2022-09-08 14:08:51 +08:00
|
|
|
def test_demo_compatibility(self):
|
|
|
|
|
self.compatibility_check()
|
|
|
|
|
|
2022-08-16 09:15:53 +08:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|