microsoft/trocr-base-printed is a forked repo from huggingface. License: None
Go to file
Joao Gante 0c708d318c Adding generation config file(s) 2023-01-24 16:57:27 +00:00
.gitattributes initial commit 2021-10-05 12:45:15 +00:00
README.md Update README.md 2022-09-19 07:32:08 +00:00
config.json Rename encoder_hidden_size to cross_attention_hidden_size 2021-10-11 12:13:21 +00:00
generation_config.json Adding generation config file(s) 2023-01-24 16:57:27 +00:00
merges.txt First commit 2021-10-05 12:50:05 +00:00
preprocessor_config.json First commit 2021-10-05 12:50:05 +00:00
pytorch_model.bin First commit 2021-10-05 12:50:05 +00:00
special_tokens_map.json First commit 2021-10-05 12:50:05 +00:00
tokenizer_config.json Remove tokenizer_file 2022-01-21 16:56:14 +00:00
vocab.json First commit 2021-10-05 12:50:05 +00:00

README.md

tags widget
trocr
image-to-text
src example_title
https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X00016469612_1.jpg Printed 1
src example_title
https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005255805_7.jpg Printed 2
src example_title
https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005745214_6.jpg Printed 3

TrOCR (base-sized model, fine-tuned on SROIE)

TrOCR model fine-tuned on the SROIE dataset. It was introduced in the paper TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models by Li et al. and first released in this repository.

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.

Model description

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.

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.

Intended uses & limitations

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.

How to use

Here is how to use this model in PyTorch:

from transformers import TrOCRProcessor, VisionEncoderDecoderModel
from PIL import Image
import requests

# load image from the IAM database (actually this model is meant to be used on printed text)
url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg'
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")

processor = TrOCRProcessor.from_pretrained('microsoft/trocr-base-printed')
model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-base-printed')
pixel_values = processor(images=image, return_tensors="pt").pixel_values

generated_ids = model.generate(pixel_values)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]

BibTeX entry and citation info

@misc{li2021trocr,
      title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models}, 
      author={Minghao Li and Tengchao Lv and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},
      year={2021},
      eprint={2109.10282},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}