vukpetar commited on
Commit
daa6f7c
1 Parent(s): 09910f0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +43 -0
README.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## TrOCR (small-sized model, fine-tuned on Synthetic Math Expression Dataset)
2
+ TrOCR model fine-tuned on the Synthetic Math Expression Dataset. 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).
3
+
4
+ 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.
5
+
6
+ ## Model description
7
+ 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.
8
+
9
+ 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.
10
+
11
+ ## Intended uses & limitations
12
+ You can use the raw model for optical character recognition (OCR) on single text-line images. See the model hub to look for fine-tuned versions on a task that interests you.
13
+
14
+ ## How to use
15
+ Here is how to use this model in PyTorch:
16
+ ```python
17
+ from transformers import VisionEncoderDecoderModel, AutoFeatureExtractor, AutoTokenizer
18
+ from PIL import Image
19
+ import requests
20
+
21
+ # load image from the IAM database
22
+ url = 'https://drive.google.com/uc?export=view&id=15dUjO44YDe1Agw_Qi8MyODRHpUFaCFw-'
23
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
24
+
25
+ feature_extractor = AutoFeatureExtractor.from_pretrained('vukpetar/trocr-small-photomath')
26
+ tokenizer = AutoTokenizer.from_pretrained("vukpetar/trocr-small-photomath")
27
+ model = VisionEncoderDecoderModel.from_pretrained('vukpetar/trocr-small-photomath')
28
+ pixel_values = feature_extractor(images=image, return_tensors="pt").pixel_values
29
+
30
+ generated_ids = model.generate(pixel_values)
31
+ generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
32
+ ```
33
+
34
+
35
+ ## BibTeX entry and citation info
36
+ @misc{li2021trocr,
37
+ title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models},
38
+ author={Minghao Li and Tengchao Lv and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},
39
+ year={2021},
40
+ eprint={2109.10282},
41
+ archivePrefix={arXiv},
42
+ primaryClass={cs.CL}
43
+ }