From e2bd3021752b10c1019b0f8dc5c0bd9459a527fc Mon Sep 17 00:00:00 2001 From: Yingda Chen Date: Thu, 28 Nov 2024 00:43:24 +0800 Subject: [PATCH] fix potential double definition for ocr pipeline (#1102) * fix potential double definition issue --------- Co-authored-by: Yingda Chen --- .../pipelines/cv/ocr_detection_pipeline.py | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/modelscope/pipelines/cv/ocr_detection_pipeline.py b/modelscope/pipelines/cv/ocr_detection_pipeline.py index c23f6e6e..5b0fbda5 100644 --- a/modelscope/pipelines/cv/ocr_detection_pipeline.py +++ b/modelscope/pipelines/cv/ocr_detection_pipeline.py @@ -27,6 +27,8 @@ RBOX_DIM = 5 OFFSET_DIM = 6 WORD_POLYGON_DIM = 8 OFFSET_VARIANCE = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1] +TF_NODE_THRESHOLD = 0.4 +TF_LINK_THRESHOLD = 0.6 @PIPELINES.register_module( @@ -39,7 +41,7 @@ class OCRDetectionPipeline(Pipeline): ```python >>> from modelscope.pipelines import pipeline - >>> ocr_detection = pipeline('ocr_detection', model='damo/cv_resnet18_ocr-detection-line-level_damo') + >>> ocr_detection = pipeline('ocr-detection', model='damo/cv_resnet18_ocr-detection-line-level_damo') >>> result = ocr_detection('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/ocr_detection.jpg') {'polygons': array([[220, 14, 780, 14, 780, 64, 220, 64], @@ -87,9 +89,9 @@ class OCRDetectionPipeline(Pipeline): tf = tf.compat.v1 tf.compat.v1.disable_eager_execution() - tf.app.flags.DEFINE_float('node_threshold', 0.4, + tf.app.flags.DEFINE_float('node_threshold', TF_NODE_THRESHOLD, 'Confidence threshold for nodes') - tf.app.flags.DEFINE_float('link_threshold', 0.6, + tf.app.flags.DEFINE_float('link_threshold', TF_LINK_THRESHOLD, 'Confidence threshold for links') tf.reset_default_graph() model_path = osp.join( @@ -192,18 +194,6 @@ class OCRDetectionPipeline(Pipeline): return result else: # for model seglink++ - import tensorflow as tf - - if tf.__version__ >= '2.0': - tf = tf.compat.v1 - - tf.compat.v1.disable_eager_execution() - - tf.app.flags.DEFINE_float('node_threshold', 0.4, - 'Confidence threshold for nodes') - tf.app.flags.DEFINE_float('link_threshold', 0.6, - 'Confidence threshold for links') - img = LoadImage.convert_to_ndarray(input) h, w, c = img.shape