diff --git a/modelscope/pipeline_inputs.py b/modelscope/pipeline_inputs.py index a10db39e..6d4f7794 100644 --- a/modelscope/pipeline_inputs.py +++ b/modelscope/pipeline_inputs.py @@ -1,6 +1,5 @@ # Copyright (c) Alibaba, Inc. and its affiliates. -import cv2 import numpy as np from PIL import Image @@ -29,7 +28,7 @@ INPUT_TYPE = { InputType.IMAGE: (str, np.ndarray, Image.Image), InputType.TEXT: str, InputType.AUDIO: (str, bytes, np.ndarray), - InputType.VIDEO: (str, np.ndarray, cv2.VideoCapture), + InputType.VIDEO: (str, np.ndarray, 'cv2.VideoCapture'), InputType.BOX: (list, np.ndarray), InputType.DICT: (dict, type(None)), InputType.LIST: (list, type(None)), @@ -39,8 +38,13 @@ INPUT_TYPE = { def check_input_type(input_type, input): expected_type = INPUT_TYPE[input_type] - assert isinstance(input, expected_type), \ - f'invalid input type for {input_type}, expected {expected_type} but got {type(input)}\n {input}' + if expected_type == 'cv2.VideoCapture': + # 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}' + else: + assert isinstance(input, expected_type), \ + f'invalid input type for {input_type}, expected {expected_type} but got {type(input)}\n {input}' TASK_INPUTS = { diff --git a/modelscope/utils/error.py b/modelscope/utils/error.py index 8128f7b0..bb29aaa0 100644 --- a/modelscope/utils/error.py +++ b/modelscope/utils/error.py @@ -125,3 +125,12 @@ You can install it with pip on linux or mac: Or you can checkout the instructions on the installation page: https://github.com/facebookresearch/fastText and follow the ones that match your environment. """ + +# docstyle-ignore +EASYNLP_IMPORT_ERROR = """ +{0} requires the easynlp library but it was not found in your environment. +You can install it with pip on linux or mac: +`pip install pai-easynlp -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html` +Or you can checkout the instructions on the +installation page: https://github.com/alibaba/EasyNLP and follow the ones that match your environment. +""" diff --git a/modelscope/utils/import_utils.py b/modelscope/utils/import_utils.py index 1678776e..b251d107 100644 --- a/modelscope/utils/import_utils.py +++ b/modelscope/utils/import_utils.py @@ -288,6 +288,7 @@ REQUIREMENTS_MAAPING = OrderedDict([ ('scipy', (is_scipy_available, SCIPY_IMPORT_ERROR)), ('cv2', (is_opencv_available, OPENCV_IMPORT_ERROR)), ('PIL', (is_pillow_available, PILLOW_IMPORT_ERROR)), + ('pai-easynlp', (is_package_available('easynlp'), EASYNLP_IMPORT_ERROR)), ('espnet2', (is_espnet_available, GENERAL_IMPORT_ERROR.replace('REQ', 'espnet'))), ('espnet', (is_espnet_available, diff --git a/requirements/cv.txt b/requirements/cv.txt index 338218b0..43eba7f9 100644 --- a/requirements/cv.txt +++ b/requirements/cv.txt @@ -21,6 +21,7 @@ moviepy>=1.0.3 networkx>=2.5 numba onnxruntime>=1.10 +opencv-python pai-easycv>=0.6.3.9 pandas psutil diff --git a/requirements/framework.txt b/requirements/framework.txt index a86c0cc5..abc08cf1 100644 --- a/requirements/framework.txt +++ b/requirements/framework.txt @@ -8,7 +8,6 @@ filelock>=3.3.0 gast>=0.2.2 jsonplus numpy -opencv-python oss2 Pillow>=6.2.0 # for pyarrow 9.0.0 event_loop core dump diff --git a/requirements/nlp.txt b/requirements/nlp.txt index 433f70f7..694fc7db 100644 --- a/requirements/nlp.txt +++ b/requirements/nlp.txt @@ -5,7 +5,6 @@ ftfy jieba>=0.42.1 matplotlib nltk -pai-easynlp pandas # protobuf version beyond 3.20.0 is not compatible with TensorFlow 1.x, therefore is discouraged. protobuf>=3.19.0,<3.21.0