This is the official repository for LOCR, the academic document PDF parser that guided by text location.
From repository:
git clone https://github.com/Merry-bee/LOCR.git
You need to download the pytorch_model.bin from Hugging Face: https://huggingface.co/Merry-bee/LOCR/tree/main.
The checkpoints directory structure can look as follows:
checkpoints/
├── config.json
├── pytorch_model.bin
├── special_tokens_map.json
├── tokenizer_config.json
└── tokenizer.json
To get predictions for a PDF run
source predict_prompt.sh
bash file: python predict_prompt.py pdf
environ:
decay decay_weight, 1 as no decay.
arguments:
pdf PDF(s) to process. Either a pdf file or a txt file containing paths of pdf files.
options:
--batchsize Batch size to use.
--checkpoint Path to checkpoint directory.
--out Output directory.
--recompute Recompute already computed PDF, discarding previous predictions.
--return_attention True when prediction.
--interaction Whether to turn on human-interactive mode.
To train or fine tune a LOCR model, run
python train_prompt.py --config config/train_LOCR.yaml
If you do not want to use wandb, run
python train_prompt.py --config config/train_LOCR.yaml --debug
To generate a dataset you need
- A training dataset and a validation dataset with
.jsonlformat. - An image directory containing the images.
- Each jsonl file contains json lines, with each line as a dict of
{'image':$image_path,'prompt':$list_of_bbox,'pretext':$list_of_tokens}, where$image_pathis the relative path to your image directory. - Run
locr.dataset.gen_seek.pyto generate.seek.mapfiles.
The data directory structure can look as follows:
dataset/
├── images
├── train.jsonl
├── train.seek.map
├── validation.jsonl
└── validation.seek.map
Run
source test.sh
@ARTICLE{2024arXiv240302127S,
author = {{Sun}, Yu and {Zhou}, Dongzhan and {Lin}, Chen and {He}, Conghui and {Ouyang}, Wanli and {Zhong}, Han-Sen},
title = "{LOCR: Location-Guided Transformer for Optical Character Recognition}",
journal = {arXiv e-prints},
keywords = {Computer Science - Computer Vision and Pattern Recognition, Computer Science - Artificial Intelligence, Computer Science - Computation and Language},
year = 2024,
month = mar,
eid = {arXiv:2403.02127},
pages = {arXiv:2403.02127},
doi = {10.48550/arXiv.2403.02127},
archivePrefix = {arXiv},
eprint = {2403.02127},
primaryClass = {cs.CV},
adsurl = {https://ui.adsabs.harvard.edu/abs/2024arXiv240302127S},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
This repository builds on top of the Donut and Nougat repository.
LOCR codebase is licensed under apache-2.0.