remove opencv-python from framework requirements and remove easynlp from nlp default requirements

Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/11119626
This commit is contained in:
wenmeng.zwm
2022-12-16 14:27:23 +08:00
parent 95ede6378e
commit 070ec00720
6 changed files with 19 additions and 6 deletions

View File

@@ -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 = {

View File

@@ -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.
"""

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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