From cb35b9c04e2ca97e353f2e434d9fb8e2e64ecf1b Mon Sep 17 00:00:00 2001 From: xfanplus Date: Wed, 10 May 2023 10:34:42 +0800 Subject: [PATCH] fix type checking of inputs for np.array (#271) * fix type checking of inputs for np.array inputs type of np.ndarray is not checked correctly. * add docstr for /preprocessor.py add docstr about np.ndarray, shape and order --- modelscope/models/cv/ocr_detection/preprocessor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modelscope/models/cv/ocr_detection/preprocessor.py b/modelscope/models/cv/ocr_detection/preprocessor.py index 4b95b3c9..d3009af8 100644 --- a/modelscope/models/cv/ocr_detection/preprocessor.py +++ b/modelscope/models/cv/ocr_detection/preprocessor.py @@ -37,7 +37,7 @@ class OCRDetectionPreprocessor(Preprocessor): inputs: - A string containing an HTTP link pointing to an image - A string containing a local path to an image - - An image loaded in PIL or opencv directly + - An image loaded in PIL(PIL.Image.Image) or opencv(np.ndarray) directly, 3 channels RGB Returns: outputs: the preprocessed image """ @@ -45,6 +45,8 @@ class OCRDetectionPreprocessor(Preprocessor): img = np.array(load_image(inputs)) elif isinstance(inputs, PIL.Image.Image): img = np.array(inputs) + elif isinstance(inputs, np.ndarray): + img = inputs else: raise TypeError( f'inputs should be either str, PIL.Image, np.array, but got {type(inputs)}'