diff --git a/data/test/images/image_safetyhat.jpg b/data/test/images/image_safetyhat.jpg new file mode 100644 index 00000000..e70b9061 --- /dev/null +++ b/data/test/images/image_safetyhat.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dca477e8a0e25bccb4966ddaebad75d7c770deb1c5e55b9b5e9f39078ea84c2 +size 168454 diff --git a/data/test/images/image_smoke.jpg b/data/test/images/image_smoke.jpg new file mode 100644 index 00000000..364bc16e --- /dev/null +++ b/data/test/images/image_smoke.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0dbbcaa0bb6b2c64b1c360f03913b7ab5386a846cc81c34825c115c41c4d672a +size 23345 diff --git a/modelscope/models/cv/tinynas_detection/tinynas_damoyolo.py b/modelscope/models/cv/tinynas_detection/tinynas_damoyolo.py index 76bfb5ee..3243e4db 100644 --- a/modelscope/models/cv/tinynas_detection/tinynas_damoyolo.py +++ b/modelscope/models/cv/tinynas_detection/tinynas_damoyolo.py @@ -7,7 +7,8 @@ from .detector import SingleStageDetector @MODELS.register_module( - Tasks.human_detection, module_name=Models.tinynas_damoyolo) + Tasks.domain_specific_object_detection, + module_name=Models.tinynas_damoyolo) @MODELS.register_module( Tasks.image_object_detection, module_name=Models.tinynas_damoyolo) class DamoYolo(SingleStageDetector): diff --git a/modelscope/outputs/outputs.py b/modelscope/outputs/outputs.py index b2cfb97b..bbd05740 100644 --- a/modelscope/outputs/outputs.py +++ b/modelscope/outputs/outputs.py @@ -219,6 +219,8 @@ TASK_OUTPUTS = { # } Tasks.image_object_detection: [OutputKeys.SCORES, OutputKeys.LABELS, OutputKeys.BOXES], + Tasks.domain_specific_object_detection: + [OutputKeys.SCORES, OutputKeys.LABELS, OutputKeys.BOXES], # video object detection result for single sample # { @@ -370,8 +372,9 @@ TASK_OUTPUTS = { # ], # "timestamps": ["hh:mm:ss", "hh:mm:ss", "hh:mm:ss"] # } - Tasks.video_single_object_tracking: - [OutputKeys.BOXES, OutputKeys.TIMESTAMPS], + Tasks.video_single_object_tracking: [ + OutputKeys.BOXES, OutputKeys.TIMESTAMPS + ], # live category recognition result for single video # { diff --git a/modelscope/pipeline_inputs.py b/modelscope/pipeline_inputs.py index 57ca561c..ffb1ac7d 100644 --- a/modelscope/pipeline_inputs.py +++ b/modelscope/pipeline_inputs.py @@ -78,6 +78,8 @@ TASK_INPUTS = { InputType.IMAGE, Tasks.image_object_detection: InputType.IMAGE, + Tasks.domain_specific_object_detection: + InputType.IMAGE, Tasks.image_segmentation: InputType.IMAGE, Tasks.portrait_matting: diff --git a/modelscope/pipelines/cv/tinynas_detection_pipeline.py b/modelscope/pipelines/cv/tinynas_detection_pipeline.py index 0932c8c7..706582b8 100644 --- a/modelscope/pipelines/cv/tinynas_detection_pipeline.py +++ b/modelscope/pipelines/cv/tinynas_detection_pipeline.py @@ -20,7 +20,8 @@ logger = get_logger() @PIPELINES.register_module( - Tasks.human_detection, module_name=Pipelines.tinynas_detection) + Tasks.domain_specific_object_detection, + module_name=Pipelines.tinynas_detection) @PIPELINES.register_module( Tasks.image_object_detection, module_name=Pipelines.tinynas_detection) class TinynasDetectionPipeline(Pipeline): diff --git a/modelscope/utils/constant.py b/modelscope/utils/constant.py index f8b97de7..d7eb48ca 100644 --- a/modelscope/utils/constant.py +++ b/modelscope/utils/constant.py @@ -108,6 +108,9 @@ class CVTasks(object): # pointcloud task pointcloud_sceneflow_estimation = 'pointcloud-sceneflow-estimation' + # domain specific object detection + domain_specific_object_detection = 'domain-specific-object-detection' + class NLPTasks(object): # nlp tasks diff --git a/tests/pipelines/test_tinynas_detection.py b/tests/pipelines/test_tinynas_detection.py index aa16a7e7..a73e7b0c 100644 --- a/tests/pipelines/test_tinynas_detection.py +++ b/tests/pipelines/test_tinynas_detection.py @@ -69,7 +69,7 @@ class TinynasObjectDetectionTest(unittest.TestCase, DemoCompatibilityCheck): @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') def test_human_detection_damoyolo(self): tinynas_object_detection = pipeline( - Tasks.human_detection, + Tasks.domain_specific_object_detection, model='damo/cv_tinynas_human-detection_damoyolo') result = tinynas_object_detection( 'data/test/images/image_detection.jpg') @@ -80,7 +80,7 @@ class TinynasObjectDetectionTest(unittest.TestCase, DemoCompatibilityCheck): @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_human_detection_damoyolo_with_image(self): tinynas_object_detection = pipeline( - Tasks.human_detection, + Tasks.domain_specific_object_detection, model='damo/cv_tinynas_human-detection_damoyolo') img = Image.open('data/test/images/image_detection.jpg') result = tinynas_object_detection(img) @@ -88,6 +88,71 @@ class TinynasObjectDetectionTest(unittest.TestCase, DemoCompatibilityCheck): OutputKeys.LABELS in result) and (OutputKeys.BOXES in result) print('results: ', result) + @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + def test_facemask_detection_damoyolo(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_facemask') + result = tinynas_object_detection( + 'data/test/images/image_detection.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_facemask_detection_damoyolo_with_image(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_facemask') + img = Image.open('data/test/images/image_detection.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) + + @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + def test_safetyhat_detection_damoyolo(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_safety-helmet') + result = tinynas_object_detection( + 'data/test/images/image_safetyhat.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_safetyhat_detection_damoyolo_with_image(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_safety-helmet') + img = Image.open('data/test/images/image_safetyhat.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) + + @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + def test_cigarette_detection_damoyolo(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_cigarette') + result = tinynas_object_detection('data/test/images/image_smoke.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_cigarette_detection_damoyolo_with_image(self): + tinynas_object_detection = pipeline( + Tasks.domain_specific_object_detection, + model='damo/cv_tinynas_object-detection_damoyolo_cigarette') + img = Image.open('data/test/images/image_smoke.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()