Views
No views yet

1from transformers import TrOCRProcessor, VisionEncoderDecoderModel
2from PIL import Image
3import requests
4
5# load image from the IAM database
6url = 'https://huggingface.co/medieval-data/trocr-medieval-print/resolve/main/images/print-1.png'
7image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
8
9processor = TrOCRProcessor.from_pretrained('medieval-data/trocr-medieval-base')
10model = VisionEncoderDecoderModel.from_pretrained('medieval-data/trocr-medieval-base')
11pixel_values = processor(images=image, return_tensors="pt").pixel_values
12
13generated_ids = model.generate(pixel_values)
14generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]1@misc{li2021trocr,
2 title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models},
3 author={Minghao Li and Tengchao Lv and Lei Cui and Yijuan Lu and Dinei Florencio and Cha Zhang and Zhoujun Li and Furu Wei},
4 year={2021},
5 eprint={2109.10282},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}1@unpublished{clerice:hal-04453952,
2 TITLE = {{CATMuS Medieval: A multilingual large-scale cross-century dataset in Latin script for handwritten text recognition and beyond}},
3 AUTHOR = {Cl{\'e}rice, Thibault and Pinche, Ariane and Vlachou-Efstathiou, Malamatenia and Chagu{\'e}, Alix and Camps, Jean-Baptiste and Gille-Levenson, Matthias and Brisville-Fertin, Olivier and Fischer, Franz and Gervers, Michaels and Boutreux, Agn{\`e}s and Manton, Avery and Gabay, Simon and O'Connor, Patricia and Haverals, Wouter and Kestemont, Mike and Vandyck, Caroline and Kiessling, Benjamin},
4 URL = {https://inria.hal.science/hal-04453952},
5 NOTE = {working paper or preprint},
6 YEAR = {2024},
7 MONTH = Feb,
8 KEYWORDS = {Historical sources ; medieval manuscripts ; Latin scripts ; benchmarking dataset ; multilingual ; handwritten text recognition},
9 PDF = {https://inria.hal.science/hal-04453952/file/ICDAR24___CATMUS_Medieval-1.pdf},
10 HAL_ID = {hal-04453952},
11 HAL_VERSION = {v1},
12}