Official Implementation of OCR-free Document Understanding Transformer (Donut) and Synthetic Document Generator (SynthDoG), ECCV 2022
Official Implementation of OCR-free Document Understanding Transformer (Donut) and Synthetic Document Generator (SynthDoG), ECCV 2022
Donut , Document understanding transformer, is a new method of document understanding that utilizes an OCR-free end-to-end Transformer model. Donut does not require off-the-shelf OCR engines/APIs, yet it shows state-of-the-art performances on various visual document understanding tasks, such as visual document classification or information extraction (a.k.a. document parsing). In addition, we present SynthDoG , Synthetic Document Generator, that helps the model pre-training to be flexible on various languages and domains.
Our academic paper, which describes our method in detail and provides full experimental results and analyses, can be found here:
OCR-free Document Understanding Transformer.
Geewook Kim, Teakgyu Hong, Moonbin Yim, JeongYeon Nam, Jinyoung Park, Jinyeong Yim, Wonseok Hwang, Sangdoo Yun, Dongyoon Han, Seunghyun Park. In ECCV 2022.
| Gradio web demos are available! |
|---|
./app.py file../misc and more receipt images are available at CORD dataset link.|Task|Sec/Img|Score|Trained Model|
|
|---|---|---|---|---|
| CORD (Document Parsing) | 0.7 /
0.7 /
1.2 | 91.3 /
91.1 /
90.9 | donut-base-finetuned-cord-v2 (1280) /
donut-base-finetuned-cord-v1 (1280) /
donut-base-finetuned-cord-v1-2560 | gradio space web demo,
google colab demo (updated at 23.06.15) |
| Train Ticket (Document Parsing) | 0.6 | 98.7 | donut-base-finetuned-zhtrainticket | google colab demo (updated at 23.06.15) |
| RVL-CDIP (Document Classification) | 0.75 | 95.3 | donut-base-finetuned-rvlcdip | gradio space web demo,
google colab demo (updated at 23.06.15) |
| DocVQA Task1 (Document VQA) | 0.78 | 67.5 | donut-base-finetuned-docvqa | gradio space web demo,
google colab demo (updated at 23.06.15) |
The links to the pre-trained backbones are here:
donut-base: trained with 64 A100 GPUs (~2.5 days), number of layers (encoder: {2,2,14,2}, decoder: 4), input size 2560x1920, swin window size 10, IIT-CDIP (11M) and SynthDoG (English, Chinese, Japanese, Korean, 0.5M x 4).donut-proto: (preliminary model) trained with 8 V100 GPUs (~5 days), number of layers (encoder: {2,2,18,2}, decoder: 4), input size 2048x1536, swin window size 8, and SynthDoG (English, Japanese, Korean, 0.4M x 3).Please see our paper for more details.
The links to the SynthDoG-generated datasets are here:
synthdog-en: English, 0.5M.synthdog-zh: Chinese, 0.5M.synthdog-ja: Japanese, 0.5M.synthdog-ko: Korean, 0.5M.To generate synthetic datasets with our SynthDoG, please see ./synthdog/README.md and our paper for details.
2023-06-15 We have updated all Google Colab demos to ensure its proper working.
2022-11-14 New version 1.0.9 is released (pip install donut-python --upgrade). See 1.0.9 Release Notes.
2022-08-12 Donut is also available at huggingface/transformers (contributed by @NielsRogge). donut-python loads the pre-trained weights from the official branch of the model repositories. See 1.0.5 Release Notes.
2022-08-05 A well-executed hands-on tutorial on donut is published at Towards Data Science (written by @estaudere).
2022-07-20 First Commit, We release our code, model weights, synthetic data and generator.
pip install donut-pythonor clone this repository and install the dependencies:
git clone https://github.com/clovaai/donut.git
cd donut/
conda create -n donut_official python=3.7
conda activate donut_official
pip install .We tested donut-python == 1.0.1 with:
Note: From several reported issues, we have noticed increased challenges in configuring the testing environment for donut-python due to recent updates in key dependency libraries. While we are actively working on a solution, we have updated the Google Colab demo (as of June 15, 2023) to ensure its proper working. For assistance, we encourage you to refer to the following demo links: CORD Colab Demo, Train Ticket Colab Demo, RVL-CDIP Colab Demo, DocVQA Colab Demo.
This repository assumes the following structure of dataset:
…metadata.jsonl file is in JSON Lines text format, i.e., .jsonl. Each line consists offile_name : relative path to the image file.ground_truth : string format (json dumped), the dictionary contains either gt_parse or gt_parses. Other fields (metadata) can be added to the dictionary but will not be used.donut interprets all tasks as a JSON prediction problem. As a result, all donut model training share a same pipeline. For training and inference, the only thing to do is preparing gt_parse or gt_parses for the task in format described below.The gt_parse follows the format of {"class" : {class_name}}, for example, {"class" : "scientific_report"} or {"class" : "presentation"}.
The gt_parse is a JSON object that contains full information of the document image, for example, the JSON object for a receipt may look like {"menu" : [{"nm": "ICE BLACKCOFFEE", "cnt": "2", ...}, ...], ...}.
The gt_parses follows the format of [{"question" : {question_sentence}, "answer" : {answer_candidate_1}}, {"question" : {question_sentence}, "answer" : {answer_candidate_2}}, ...], for example, [{"question" : "what is the model name?", "answer" : "donut"}, {"question" : "what is the model name?", "answer" : "document understanding transformer"}].
gt_parses should be a list of dictionary that contains a pair of question and answer.The gt_parse looks like {"text_sequence" : "word1 word2 word3 ... "}
gt_parse. See ./synthdog/README.md for details.This is the configuration of Donut model training on CORD dataset used in our experiment. We ran this with a single NVIDIA A100 GPU.
…Some important arguments:
--config : config file path for model training.--pretrained_model_name_or_path : string format, model name in Hugging Face modelhub or local path.--dataset_name_or_paths : string format (json dumped), list of dataset names in Hugging Face datasets or local paths.--result_path : file path to save model outputs/artifacts.--exp_version : used for experiment versioning. The output files are saved at {result_path}/{exp_version}/*With the trained model, test images and ground truth parses, you can get inference results and accuracy scores.
python test.py --dataset_name_or_path naver-clova-ix/cord-v2 --pretrained_model_name_or_path ./result/train_cord/test_experiment --save_path ./result/output.json
100%|█████████████| 100/100 [00:35<00:00, 2.80it/s]
Total number of samples: 100, Tree Edit Distance (TED) based accuracy score: 0.9129639764131697, F1 accuracy score: 0.8406020841373987Some important arguments:
--dataset_name_or_path : string format, the target dataset name in Hugging Face datasets or local path.--pretrained_model_name_or_path : string format, the model name in Hugging Face modelhub or local path.--save_path: file path to save predictions and scores.If you find this work useful to you, please cite:
@inproceedings{kim2022donut,
title = {OCR-Frapp.py Failing for Python 3.9
Colab Demo CORD (Document Parsing) is Broken
Model inferencing from the saved files generated by train.py
Issue encountered while training the cord-v2
Tree Edit Distance (TED) based accuracy score: 0.0, F1 accuracy score: 0.0 on test data
How many documents(invoices) are required for training model for document information extraction?
Got wrong inference result
Questions about SynthDoG synthetic data
Reading order for pseudo-OCR pre-training task
dataset