Add model card
Browse files
README.md
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# TrOCR (base-sized model, fine-tuned on SROIE)
|
2 |
+
|
3 |
+
TrOCR model fine-tuned on the [SROIE dataset](https://rrc.cvc.uab.es/?ch=13). It was introduced in the paper [TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models](https://arxiv.org/abs/2109.10282) by Li et al. and first released in [this repository](https://github.com/microsoft/unilm/tree/master/trocr).
|
4 |
+
|
5 |
+
Disclaimer: The team releasing TrOCR did not write a model card for this model so this model card has been written by the Hugging Face team.
|
6 |
+
|
7 |
+
## Model description
|
8 |
+
|
9 |
+
The TrOCR model is an encoder-decoder model, consisting of an image Transformer as encoder, and a text Transformer as decoder. The image encoder was initialized from the weights of BEiT, while the text decoder was initialized from the weights of RoBERTa.
|
10 |
+
|
11 |
+
Images are presented to the model as a sequence of fixed-size patches (resolution 16x16), which are linearly embedded. One also adds absolute position embeddings before feeding the sequence to the layers of the Transformer encoder. Next, the Transformer text decoder autoregressively generates tokens.
|
12 |
+
|
13 |
+
## Intended uses & limitations
|
14 |
+
|
15 |
+
You can use the raw model for optical character recognition (OCR) on single text-line images. See the [model hub](https://huggingface.co/models?search=microsoft/trocr) to look for fine-tuned versions on a task that interests you.
|
16 |
+
|
17 |
+
### How to use
|
18 |
+
|
19 |
+
Here is how to use this model in PyTorch:
|
20 |
+
|
21 |
+
```python
|
22 |
+
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
23 |
+
from PIL import Image
|
24 |
+
import requests
|
25 |
+
|
26 |
+
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
27 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
28 |
+
|
29 |
+
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-printed')
|
30 |
+
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-printed')
|
31 |
+
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
32 |
+
|
33 |
+
generated_ids = model.generate(pixel_values)
|
34 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
35 |
+
```
|
36 |
+
|
37 |
+
### BibTeX entry and citation info
|
38 |
+
|
39 |
+
```bibtex
|
40 |
+
@misc{li2021trocr,
|
41 |
+
title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models},
|
42 |
+
author={Minghao Li and Tengchao Lv and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},
|
43 |
+
year={2021},
|
44 |
+
eprint={2109.10282},
|
45 |
+
archivePrefix={arXiv},
|
46 |
+
primaryClass={cs.CL}
|
47 |
+
}
|
48 |
+
```
|