2023-02-09 06:35:00 +00:00
|
|
|
# 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.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-05-22 10:53:18 +08:00
|
|
|
class TrafficSignDetectionTest(unittest.TestCase):
|
2023-02-09 06:35:00 +00:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.task = Tasks.domain_specific_object_detection
|
|
|
|
|
self.model_id = 'damo/cv_tinynas_object-detection_damoyolo_traffic_sign'
|
|
|
|
|
|
|
|
|
|
@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,
|
2025-05-13 22:52:57 +08:00
|
|
|
model='damo/cv_tinynas_object-detection_damoyolo_traffic_sign',
|
|
|
|
|
trust_remote_code=True)
|
2023-02-09 06:35:00 +00:00
|
|
|
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()
|