From a8a0cef71ee3a1d123279069f7f3b8d739382f00 Mon Sep 17 00:00:00 2001 From: "lanjinpeng.ljp" Date: Thu, 9 Feb 2023 06:35:00 +0000 Subject: [PATCH] support traffic-sign detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持cv垂类交通标识检测模型 Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/11535569 --- data/test/images/image_traffic_sign.jpg | 3 ++ .../pipelines/test_traffic_sign_detection.py | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 data/test/images/image_traffic_sign.jpg create mode 100644 tests/pipelines/test_traffic_sign_detection.py diff --git a/data/test/images/image_traffic_sign.jpg b/data/test/images/image_traffic_sign.jpg new file mode 100644 index 00000000..c0e4276f --- /dev/null +++ b/data/test/images/image_traffic_sign.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6ab556a1d69010cfe6dd136ff3fbd17ed122c6d0c3509667ef40a656bc18464 +size 87334 diff --git a/tests/pipelines/test_traffic_sign_detection.py b/tests/pipelines/test_traffic_sign_detection.py new file mode 100644 index 00000000..5404649d --- /dev/null +++ b/tests/pipelines/test_traffic_sign_detection.py @@ -0,0 +1,48 @@ +# Copyright (c) Alibaba, Inc. and its affiliates. + +import unittest + +from PIL import Image + +from modelscope.outputs import OutputKeys +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks +from modelscope.utils.demo_utils import DemoCompatibilityCheck +from modelscope.utils.test_utils import test_level + + +class TrafficSignDetectionTest(unittest.TestCase, DemoCompatibilityCheck): + + def setUp(self) -> None: + self.task = Tasks.domain_specific_object_detection + self.model_id = 'damo/cv_tinynas_object-detection_damoyolo_traffic_sign' + + @unittest.skip('demo compatibility test is only enabled on a needed-basis') + def test_demo_compatibility(self): + self.compatibility_check() + + @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + def test_traffic_sign_detection_damoyolo(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_traffic_sign') + result = tinynas_object_detection( + 'data/test/images/image_traffic_sign.jpg') + assert result and (OutputKeys.SCORES in result) and ( + OutputKeys.LABELS in result) and (OutputKeys.BOXES in result) + print('results: ', result) + + @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') + def test_traffic_sign_detection_damoyolo_with_image(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_traffic_sign') + img = Image.open('data/test/images/image_traffic_sign.jpg') + result = tinynas_object_detection(img) + assert result and (OutputKeys.SCORES in result) and ( + OutputKeys.LABELS in result) and (OutputKeys.BOXES in result) + print('results: ', result) + + +if __name__ == '__main__': + unittest.main()