Upload README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,59 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
tags:
|
3 |
+
- mgp-str
|
4 |
+
- image-to-text
|
5 |
+
widget:
|
6 |
+
- src: https://github.com/AlibabaResearch/AdvancedLiterateMachinery/blob/main/OCR/MGP-STR/demo_imgs/IIIT5k_HOUSE.png
|
7 |
+
example_title: Example 1
|
8 |
+
- src: https://github.com/AlibabaResearch/AdvancedLiterateMachinery/blob/main/OCR/MGP-STR/demo_imgs/IIT5k_EVERYONE.png
|
9 |
+
example_title: Example 2
|
10 |
+
- src: https://github.com/AlibabaResearch/AdvancedLiterateMachinery/blob/main/OCR/MGP-STR/demo_imgs/CUTE80_KINGDOM.png
|
11 |
+
example_title: Example 3
|
12 |
---
|
13 |
+
|
14 |
+
# MGP-STR (base-sized model)
|
15 |
+
|
16 |
+
MGP-STR base-sized model is trained on MJSynth and SynthText. It was introduced in the paper [Multi-Granularity Prediction for Scene Text Recognition](https://arxiv.org/abs/2209.03592) and first released in [this repository](https://github.com/AlibabaResearch/AdvancedLiterateMachinery/tree/main/OCR/MGP-STR).
|
17 |
+
|
18 |
+
## Model description
|
19 |
+
|
20 |
+
MGP-STR is pure vision STR model, consisting of ViT and specially designed A^3 modules. The ViT module was initialized from the weights of DeiT-base, except the patch embedding model, due to the inconsistent input size.
|
21 |
+
|
22 |
+
Images (32x128) are presented to the model as a sequence of fixed-size patches (resolution 4x4), which are linearly embedded. One also adds absolute position embeddings before feeding the sequence to the layers of the ViT module. Next, A^3 module selects a meaningful combination from the tokens of ViT output and integrates them into one output token corresponding to a specific character. Moreover, subword classification heads based on BPE A^3 module and WordPiece A^3 module are devised for subword predictions, so that the language information can be implicitly modeled. Finally, these multi-granularity predictions (character, subword and even word) are merged via a simple and effective fusion strategy.
|
23 |
+
|
24 |
+
## Intended uses & limitations
|
25 |
+
|
26 |
+
You can use the raw model for optical character recognition (OCR) on text images. See the [model hub](https://huggingface.co/models?search=alibaba-damo/mgp-str) to look for fine-tuned versions on a task that interests you.
|
27 |
+
|
28 |
+
### How to use
|
29 |
+
|
30 |
+
Here is how to use this model in PyTorch:
|
31 |
+
|
32 |
+
```python
|
33 |
+
from transformers import MGPSTRProcessor, MGPSTRModel
|
34 |
+
import requests
|
35 |
+
from PIL import Image
|
36 |
+
|
37 |
+
processor = MGPSTRProcessor.from_pretrained('alibaba-damo/mgp-str-base')
|
38 |
+
model = MGPSTRModel.from_pretrained('alibaba-damo/mgp-str-base')
|
39 |
+
|
40 |
+
# load image from the IIIT-5k dataset
|
41 |
+
url = "https://i.postimg.cc/ZKwLg2Gw/367-14.png"
|
42 |
+
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
43 |
+
|
44 |
+
pixel_values = processor(image, return_tensors="pt").pixel_values
|
45 |
+
generated_ids, attens = model(pixel_values)
|
46 |
+
|
47 |
+
generated_text = processor.batch_decode(generated_ids)['generated_text']
|
48 |
+
```
|
49 |
+
|
50 |
+
### BibTeX entry and citation info
|
51 |
+
|
52 |
+
```bibtex
|
53 |
+
@inproceedings{ECCV2022mgp_str,
|
54 |
+
title={Multi-Granularity Prediction for Scene Text Recognition},
|
55 |
+
author={Peng Wang, Cheng Da, and Cong Yao},
|
56 |
+
booktitle = {ECCV},
|
57 |
+
year={2022}
|
58 |
+
}
|
59 |
+
```
|