Downloads · 30 days
1.1K
2% of all-time downloads
agomberto/trocr-large-handwritten-fr
trocr-large-handwritten-fr is a image-to-text model from agomberto. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as mit.
TrOCR handwritten has not yet released for French, so we trained a French model for PoC purpose. Based on this model, it is recommended to collect more data to additionally train the 1st stage or perform fine-tuning a…
Downloads · 30 days
1.1K
2% of all-time downloads
All-time downloads
61.6K
Public
Repo size
24.6 GB
Likes
2
Public
Click a slice to open those files.
.bin2.2 GB · 100%
From the Hugging Face model README
TrOCR handwritten has not yet released for French, so we trained a French model for PoC purpose. Based on this model, it is recommended to collect more data to additionally train the 1st stage or perform fine-tuning as the 2nd stage.
It's a special case of the English large handwritten trOCR model introduced in the paper TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models by Li et al. and first released in this repository as a TrOCR model fine-tuned on the IAM dataset. We worked with Marie Beigelman on this.
We decided to fine-tuned in two steps on two datasets and one generated dataset:
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.
You can use the raw model for optical character recognition (OCR) on single text-line images.
We used heuristic parameters without separate hyperparameter tuning.
For the dev set we got those results
For the test set we got those results
Here is how to use this model in PyTorch:
from transformers import TrOCRProcessor, VisionEncoderDecoderModel, AutoTokenizer
from PIL import Image
import requests
url = "https://github.com/agombert/trocr-base-printed-fr/blob/main/sample_imgs/5.jpg"
response = requests.get(url)
img = Image.open(BytesIO(response.content))
processor = TrOCRProcessor.from_pretrained('microsoft/trocr-large-handwritten')
model = VisionEncoderDecoderModel.from_pretrained('agomberto/trocr-large-handwritten-fr')
tokenizer = AutoTokenizer.from_pretrained('agomberto/trocr-large-handwritten-fr')
pixel_values = (processor(images=image, return_tensors="pt").pixel_values)
generated_ids = model.generate(pixel_values)
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
@miscellaneous{
author = {Arnault Gombert & Marie Beigelman},
title = {TrOCR in French: adapt to french archives},
year = {2023}
}