模型:

alibaba-damo/mgp-str-base

英文

MGP-STR(基于基准大小的模型)

MGP-STR基于MJSynth和SynthText进行训练。该模型在论文 Multi-Granularity Prediction for Scene Text Recognition 中介绍,并在 this repository 中首次发布。

模型描述

MGP-STR是一个纯粹的视觉STR模型,由ViT和特别设计的A^3模块组成。ViT模块是从DeiT-base的权重初始化的,除了补丁嵌入模型,因为输入大小不一致。

图像(32x128)以固定大小的补丁序列(分辨率4x4)的形式呈现给模型,这些补丁会进行线性嵌入。在将序列输入到ViT模块的层之前,还会添加绝对位置嵌入。接下来,A^3模块从ViT输出的标记中选择一个有意义的组合,并将它们整合成一个对应特定字符的输出标记。此外,基于BPE A^3模块和WordPiece A^3模块的子词分类头被设计用于子词预测,以便可以隐式地建模语言信息。最后,通过简单而有效的融合策略将这些多粒度预测(字符、子词甚至单词)合并。

意图和限制

您可以使用原始模型对文本图像进行光学字符识别(OCR)。请查看 model hub 以寻找您感兴趣的任务的精调版本。

如何使用

以下是在PyTorch中使用此模型的方法:

from transformers import MgpstrProcessor, MgpstrForSceneTextRecognition
import requests
from PIL import Image

processor = MgpstrProcessor.from_pretrained('alibaba-damo/mgp-str-base')
model = MgpstrForSceneTextRecognition.from_pretrained('alibaba-damo/mgp-str-base')

# load image from the IIIT-5k dataset
url = "https://i.postimg.cc/ZKwLg2Gw/367-14.png"
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")

pixel_values = processor(images=image, return_tensors="pt").pixel_values
outputs = model(pixel_values)

generated_text = processor.batch_decode(outputs.logits)['generated_text']

BibTeX条目和引用信息

@inproceedings{ECCV2022mgp_str,
  title={Multi-Granularity Prediction for Scene Text Recognition},
  author={Peng Wang, Cheng Da, and Cong Yao},
  booktitle = {ECCV},
  year={2022}
}