2022-06-21 11:56:52 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.pipelines.base import Pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-08-22 23:04:31 +08:00
|
|
|
@unittest.skip('For tensorflow 2.x compatible')
|
2023-05-14 23:41:40 +08:00
|
|
|
class OCRDetectionTest(unittest.TestCase):
|
2022-06-21 11:56:52 +08:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
|
self.model_id = 'damo/cv_resnet18_ocr-detection-line-level_damo'
|
2022-12-28 06:26:15 +08:00
|
|
|
self.model_id_vlpt = 'damo/cv_resnet50_ocr-detection-vlpt'
|
2023-02-10 05:02:59 +00:00
|
|
|
self.model_id_db = 'damo/cv_resnet18_ocr-detection-db-line-level_damo'
|
2023-05-31 21:32:46 +08:00
|
|
|
self.model_id_db_nas = 'damo/cv_proxylessnas_ocr-detection-db-line-level_damo'
|
2022-06-21 11:56:52 +08:00
|
|
|
self.test_image = 'data/test/images/ocr_detection.jpg'
|
2022-12-28 06:26:15 +08:00
|
|
|
self.test_image_vlpt = 'data/test/images/ocr_detection_vlpt.jpg'
|
2022-09-08 14:08:51 +08:00
|
|
|
self.task = Tasks.ocr_detection
|
2022-06-21 11:56:52 +08:00
|
|
|
|
|
|
|
|
def pipeline_inference(self, pipeline: Pipeline, input_location: str):
|
|
|
|
|
result = pipeline(input_location)
|
|
|
|
|
print('ocr detection results: ')
|
|
|
|
|
print(result)
|
|
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-06-28 14:03:01 +08:00
|
|
|
def test_run_with_model_from_modelhub(self):
|
|
|
|
|
ocr_detection = pipeline(Tasks.ocr_detection, model=self.model_id)
|
|
|
|
|
self.pipeline_inference(ocr_detection, self.test_image)
|
|
|
|
|
|
2022-12-28 06:26:15 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_vlpt_with_model_from_modelhub(self):
|
|
|
|
|
ocr_detection = pipeline(Tasks.ocr_detection, model=self.model_id_vlpt)
|
|
|
|
|
self.pipeline_inference(ocr_detection, self.test_image_vlpt)
|
|
|
|
|
|
2023-02-10 05:02:59 +00:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_db_with_model_from_modelhub(self):
|
|
|
|
|
ocr_detection = pipeline(Tasks.ocr_detection, model=self.model_id_db)
|
|
|
|
|
self.pipeline_inference(ocr_detection, self.test_image)
|
|
|
|
|
|
2023-05-31 21:32:46 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
|
|
|
|
def test_run_with_dbnas_with_model_from_modelhub(self):
|
|
|
|
|
ocr_detection = pipeline(
|
|
|
|
|
Tasks.ocr_detection,
|
|
|
|
|
model=self.model_id_db_nas,
|
|
|
|
|
model_revision='v1.0.0',
|
|
|
|
|
)
|
|
|
|
|
self.pipeline_inference(ocr_detection, self.test_image)
|
|
|
|
|
|
2022-06-21 20:04:25 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
2022-06-21 11:56:52 +08:00
|
|
|
def test_run_modelhub_default_model(self):
|
|
|
|
|
ocr_detection = pipeline(Tasks.ocr_detection)
|
|
|
|
|
self.pipeline_inference(ocr_detection, self.test_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|