读光-文字检测-轻量化端侧DBNet行检测模型-中英-通用领域

我要开发同款
匿名用户2024年07月31日
38阅读
所属分类aipytorch、读光、文字识别、文字检测、Alibaba、OCR、cv
开源地址https://modelscope.cn/models/iic/cv_proxylessnas_ocr-detection-db-line-level_damo
授权协议Apache License 2.0

作品详情

读光文字检测

News

  • 2023年10月:
    • 新增DBNet通用场景模型和轻量化端侧模型转onnx和onnx推理功能
  • 2023年6月:
  • 2023年3月:
    • 新增DBNet训练/微调流程,支持自定义参数及数据集,详见代码示例。
  • 2023年2月:

传送门

各场景文本检测模型:

各场景文本识别模型:

整图OCR能力:

轻量化模型DEMO:

欢迎使用!

模型描述

本模型是基于分割的文字检测方法,把文字行的区域分割文字中心区域和文字边界区域,通过处理得到文字完整区域,最后得到文字区域的外接框。详见:DBNet(Paper) 本模型基于proxyless进行nas搜索得到5M backbone,模型集成中。

期望模型使用方式以及适用范围

本模型主要用于给输入图片输出图中文字外接框坐标,具体地,模型输出的框的坐标为文字框四边形的四个角点的坐标,左上角为第一个点,按照顺时针的顺序依次输出各个点的坐标,分别为(x1,y1)(x2,y2)(x3,y3)(x4,y4)。用户可以自行尝试各种输入图片。具体调用方式请参考代码示例。

如何使用

在安装完成ModelScope之后即可使用ocr-detection的能力。

预处理和后处理

测试时的主要预处理和后处理如下:

  • Resize Pad(预处理): 输入图片短边resize到736,短边等比例缩放,并且补pad到长短边相等
  • threshold后处理): thresh和box_thresh采用0.2和0.3值

代码范例

from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
ocr_detection = pipeline(Tasks.ocr_detection, model='damo/cv_proxylessnas_ocr-detection-db-line-level_damo', model_revision='v1.0.0')
result = ocr_detection('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/ocr_detection.jpg')
print(result)

完整OCR能力体验

如果想体验完整的OCR能力,对整图中的文字进行检测识别,可以体验创空间应用。对于文字检测模型和文字识别模型的串联,可以参考说明文档

模型局限性以及可能的偏差

  • 模型是在特定中英文数据集上训练的,在其他场景和语言的数据上有可能产生一定偏差,请用户自行评测后决定如何使用。
  • 当前版本在python3.7环境CPU和单GPU环境测试通过,其他环境下可用性待测试

转onnx和onnx推理

# 导出模型
import os
import shutil
import tempfile
from modelscope.models import Model
from modelscope.utils.constant import Tasks
from modelscope.exporters import Exporter
tmp_dir = tempfile.TemporaryDirectory().name
os.makedirs(tmp_dir, exist_ok=True)
model_id = 'damo/cv_proxylessnas_ocr-detection-db-line-level_damo'
model = Model.from_pretrained(model_id)
Exporter.from_model(model).export_onnx(
    input_shape=(1,3,800,800), output_dir=tmp_dir)

# 使用模型
import cv2
import numpy as np
import onnxruntime as ort
from modelscope.models.cv.ocr_detection.utils import boxes_from_bitmap
## 预处理
image = cv2.imread(image_path)
height, width, _ = image.shape
image_resize = cv2.resize(image, (800,800))        
image_resize = image_resize - np.array([123.68, 116.78, 103.94], dtype=np.float32)
image_resize /= 255.
image_resize = np.expand_dims(image_resize.transpose(2, 0, 1), axis=0)
## onnx推理
ort_session = ort.InferenceSession(self.tmp_dir+'/model.onnx')
outputs = ort_session.run(['pred'], {'images': image_resize})
## 后处理
thresh = 0.2
pred = outputs[0]
segmentation = pred > thresh
boxes, scores = boxes_from_bitmap(pred, segmentation, width,
                                      height, is_numpy=True) 

引用

 @inproceedings{liao2020real,
  author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang},
  title={Real-time Scene Text Detection with Differentiable Binarization},
  booktitle={Proc. AAAI},
  year={2020}
}
@inproceedings{
  cai2018proxylessnas,
  title={Proxyless{NAS}: Direct Neural Architecture Search on Target Task and Hardware},
  author={Han Cai and Ligeng Zhu and Song Han},
  booktitle={International Conference on Learning Representations},
  year={2019},
  url={https://arxiv.org/pdf/1812.00332.pdf},
}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论