From a01e29ceb06a78ebfd8bdc6fca0d0b072d210fe1 Mon Sep 17 00:00:00 2001 From: "wenmeng.zwm" Date: Mon, 26 Dec 2022 09:59:59 +0800 Subject: [PATCH] fix check video type cv2.VideoCapture and add unittest Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/11181951 --- modelscope/pipeline_inputs.py | 6 +++--- tests/pipelines/test_body_3d_keypoints.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/modelscope/pipeline_inputs.py b/modelscope/pipeline_inputs.py index 50818dff..adb9fe23 100644 --- a/modelscope/pipeline_inputs.py +++ b/modelscope/pipeline_inputs.py @@ -38,10 +38,10 @@ INPUT_TYPE = { def check_input_type(input_type, input): expected_type = INPUT_TYPE[input_type] - if expected_type == 'cv2.VideoCapture': + if input_type == InputType.VIDEO: # special type checking using class name, to avoid introduction of opencv dependency into fundamental framework. - assert type(input).__name__ == 'VideoCapture',\ - f'invalid input type for {input_type}, expected cv2.VideoCapture but got {type(input)}\n {input}' + assert type(input).__name__ == 'VideoCapture' or isinstance(input, expected_type),\ + f'invalid input type for {input_type}, expected {expected_type} but got {type(input)}\n {input}' else: assert isinstance(input, expected_type), \ f'invalid input type for {input_type}, expected {expected_type} but got {type(input)}\n {input}' diff --git a/tests/pipelines/test_body_3d_keypoints.py b/tests/pipelines/test_body_3d_keypoints.py index 6e671d2e..6f73a243 100644 --- a/tests/pipelines/test_body_3d_keypoints.py +++ b/tests/pipelines/test_body_3d_keypoints.py @@ -39,9 +39,7 @@ class Body3DKeypointsTest(unittest.TestCase, DemoCompatibilityCheck): if not cap.isOpened(): raise Exception('modelscope error: %s cannot be decoded by OpenCV.' % (self.test_video)) - pipeline_input = self.test_video - self.pipeline_inference( - body_3d_keypoints, pipeline_input=pipeline_input) + self.pipeline_inference(body_3d_keypoints, pipeline_input=cap) @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') def test_demo_compatibility(self):