2022-07-29 11:48:51 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
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 ObjectDetectionTest(unittest.TestCase):
|
2022-09-08 14:08:51 +08:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.task = Tasks.human_detection
|
|
|
|
|
self.model_id = 'damo/cv_resnet18_human-detection'
|
2022-07-29 11:48:51 +08:00
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
|
|
|
|
def test_object_detection(self):
|
|
|
|
|
input_location = 'data/test/images/image_detection.jpg'
|
|
|
|
|
model_id = 'damo/cv_vit_object-detection_coco'
|
2022-08-02 12:02:31 +08:00
|
|
|
object_detect = pipeline(Tasks.image_object_detection, model=model_id)
|
2022-07-29 11:48:51 +08:00
|
|
|
result = object_detect(input_location)
|
2022-10-17 14:06:07 +08:00
|
|
|
print(result)
|
2022-07-29 11:48:51 +08:00
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_object_detection_with_default_task(self):
|
|
|
|
|
input_location = 'data/test/images/image_detection.jpg'
|
2022-08-02 12:02:31 +08:00
|
|
|
object_detect = pipeline(Tasks.image_object_detection)
|
2022-07-29 11:48:51 +08:00
|
|
|
result = object_detect(input_location)
|
2022-10-17 14:06:07 +08:00
|
|
|
print(result)
|
2022-07-29 11:48:51 +08:00
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-07-29 11:48:51 +08:00
|
|
|
def test_human_detection(self):
|
|
|
|
|
input_location = 'data/test/images/image_detection.jpg'
|
|
|
|
|
model_id = 'damo/cv_resnet18_human-detection'
|
|
|
|
|
human_detect = pipeline(Tasks.human_detection, model=model_id)
|
|
|
|
|
result = human_detect(input_location)
|
2022-10-17 14:06:07 +08:00
|
|
|
print(result)
|
2022-07-29 11:48:51 +08:00
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_human_detection_with_default_task(self):
|
|
|
|
|
input_location = 'data/test/images/image_detection.jpg'
|
|
|
|
|
human_detect = pipeline(Tasks.human_detection)
|
|
|
|
|
result = human_detect(input_location)
|
2022-10-17 14:06:07 +08:00
|
|
|
print(result)
|
2022-07-29 11:48:51 +08:00
|
|
|
|
2023-05-22 10:53:18 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
2022-10-12 19:53:14 +08:00
|
|
|
def test_image_object_detection_auto_pipeline(self):
|
2023-05-22 10:53:18 +08:00
|
|
|
# TODO: to be fixed in the future
|
2022-10-12 19:53:14 +08:00
|
|
|
model_id = 'damo/cv_yolox_image-object-detection-auto'
|
|
|
|
|
test_image = 'data/test/images/auto_demo.jpg'
|
|
|
|
|
|
|
|
|
|
image_object_detection_auto = pipeline(
|
|
|
|
|
Tasks.image_object_detection, model=model_id)
|
|
|
|
|
|
2022-10-17 20:30:42 +08:00
|
|
|
result = image_object_detection_auto(test_image)
|
2022-10-12 19:53:14 +08:00
|
|
|
image_object_detection_auto.show_result(test_image, result,
|
|
|
|
|
'auto_demo_ret.jpg')
|
|
|
|
|
|
2023-05-22 10:53:18 +08:00
|
|
|
@unittest.skip('skip test in current test level: no pipeline implemented')
|
2023-02-09 09:39:08 +00:00
|
|
|
def test_image_object_detection_dino_pipeline(self):
|
|
|
|
|
model_id = 'damo/cv_swinl_image-object-detection_dino'
|
|
|
|
|
test_image = 'data/test/images/image_detection.jpg'
|
|
|
|
|
image_object_detection_dino = pipeline(
|
|
|
|
|
Tasks.image_object_detection, model=model_id)
|
|
|
|
|
result = image_object_detection_dino(test_image)
|
|
|
|
|
print(result)
|
|
|
|
|
|
2022-07-29 11:48:51 +08:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|