TrOCR-ru (base-sized model, fine-tuned on Cyrillic Handwriting Dataset)
Model Details
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.
Uses
Here is how to use this model in PyTorch:
1from transformers import TrOCRProcessor, VisionEncoderDecoderModel
2from PIL import Image
3import requests
4
5image = Image.open("<image file path or url>").convert("RGB")
6
7processor = TrOCRProcessor.from_pretrained('kazars24/trocr-base-handwritten-ru')
8model = VisionEncoderDecoderModel.from_pretrained('kazars24/trocr-base-handwritten-ru')
9
10pixel_values = processor(images=image, return_tensors="pt").pixel_values
11generated_ids = model.generate(pixel_values)
12generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
Training Details
Training Data
Cyrillic Handwriting Dataset for OCR tasks, which is composed of 73830 segments of handwriting texts (crops) in Russian and splited into train, and test sets with a split of 95%, 5%, respectively. The dataset is provided by
SHIFT Lab CFT.
Number of training examples: 57827
Number of validation examples: 14457
Training Hyperparameters
5 epochs and default hyperparameters.
Metrics
Character error rate (CER)
Results
Training Loss: 0.026100
Validation Loss: 0.120961
CER: 0.048542