nielsr HF staff commited on
Commit
8f381d4
1 Parent(s): 6afcdf2

Add model card

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