philschmid HF staff commited on
Commit
3419651
1 Parent(s): e41851a

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -0
README.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - trocr
4
+ - image-to-text
5
+ ---
6
+
7
+ # TrOCR (base-sized model, fine-tuned on SROIE)
8
+
9
+ 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).
10
+
11
+ 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.
12
+
13
+ ## Model description
14
+
15
+ 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.
16
+
17
+ 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.
18
+
19
+ ## Intended uses & limitations
20
+
21
+ 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.
22
+
23
+ ### How to use
24
+
25
+ Here is how to use this model in PyTorch:
26
+
27
+ ```python
28
+ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
29
+ from PIL import Image
30
+ import requests
31
+
32
+ # load image from the IAM database (actually this model is meant to be used on printed text)
33
+ url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg'
34
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
35
+
36
+ processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-printed')
37
+ model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-printed')
38
+ pixel_values = processor(images=image, return_tensors="pt").pixel_values
39
+
40
+ generated_ids = model.generate(pixel_values)
41
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
42
+ ```
43
+
44
+ ### BibTeX entry and citation info
45
+
46
+ ```bibtex
47
+ @misc{li2021trocr,
48
+ title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models},
49
+ author={Minghao Li and Tengchao Lv and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},
50
+ year={2021},
51
+ eprint={2109.10282},
52
+ archivePrefix={arXiv},
53
+ primaryClass={cs.CL}
54
+ }
55
+ ```