Handwritten Text Recognition and Character Detection
Python
174
36 commits
updated Sep 28, 2025
This repository is the official implementation for General Detection-based Text Line Recognition, the paper is available on arXiv.
This repository builds on the code for DINO-DETR, the official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection". We present a model that adapts DINO-DETR for text recognition as a detection and recognition task. The model is pretrained on synthetic data using the same loss as DINO-DETR and then fine-tuned on a real dataset with CTC loss.
The model was trained with python=3.11.0, pytorch=2.1.0, cuda=11.8 and builds on the DETR-variants DINO/DN/DAB and Deformable-DETR.
pip install -r requirements.txt
python models/dino/ops/setup.py build install # 'cuda not available', run => export CUDA_HOME=/usr/local/cuda-<version>
# unit test (should see all checking is True) # could output an outofmemory error
python models/dino/ops/test.py
Datasets should be placed in the appropriate folder specified in datasets/config.json. We preprocess the images and annotations for the IAM dataset, while all other datasets are used in their original form. For each dataset (except IAM), a charset file (.pkl) is required. Charset files can be found in the folder data.
Handwritten
Chinese The official website is here. Images and annotations are provide only in bytes format for these datasets.
Ciphers The ciphers borg and copiale are available here. The charset files are provided in the folder data.
Pretrained checkpoints can be found here. The folder includes the weights of the following pretrained models:
Finetuned checkpoints can be found here.
Checkpoints should be organized as follows:
logs/
└── IAM/
└── checkpoint.pth
└── other_model/
└── checkpoint.pth
...
Pretraining scipts are available in scripts/pretraining.
You need to download the folder resources (background, fonts, noises, texts) and place it in the folder dataset.
To train models with random erasing:
sh scripts/pretraining/Synthetic_english_w_masking.sh
sh scripts/pretraining/Synthetic_german_w_masking.sh
sh scripts/pretraining/Synthetic_french_w_masking.sh
sh scripts/pretraining/Synthetic_general.sh
You need the dataset CASIA v1 [here]
To train a model with random erasing
sh scripts/pretraining/Synthetic_english.sh
Then for instances to train a model for chinese with random erasing:
bash scripts/pretraining/Synthetic_chinese_w_masking.sh
Finetuning occurs in two stages. The scripts are available in scripts/finetuning.. For Step 1 it is expected that a model is pretrained is placed in the folder logs/your_model_name.
Use the scripts in scripts/evaluating to evaluate the model on the different datasets.
We provide our N-gran models for RIMES, READ and IAM here. We strongly advice to create a separate environment for the ngram model and to install the libraries in the ngram/mini_guide.md. To run an evalutation with the ngram model:
bash python ngram/clean_gen_ngram_preds.py --config_path ngram/IAM.yaml
bash python ngram/clean_gen_ngram_preds.py --config_path ngram/READ.yaml
bash python ngram/clean_gen_ngram_preds.py --config_path ngram/RIMES.yaml
To train you own ngram model, follow the instructions in the ngram/mini_guide.md
If you find this code useful, don't forget to star the repo :star: and cite the papers :point_down:
@article{baena2024DTLR, title={General Detection-based Text Line Recognition},
author={Raphael Baena and Syrine Kalleli and Mathieu Aubry},
booktitle={NeurIPS},
year={2024}},
url={https://arxiv.org/abs/2409.17095},
29 commits
7 commits
Python
53.5%
Jupyter Notebook
39.8%
Cuda
5.3%
Handwritten Text Recognition and Character Detection
Python
174
36 commits
updated Sep 28, 2025
This repository is the official implementation for General Detection-based Text Line Recognition, the paper is available on arXiv.
This repository builds on the code for DINO-DETR, the official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection". We present a model that adapts DINO-DETR for text recognition as a detection and recognition task. The model is pretrained on synthetic data using the same loss as DINO-DETR and then fine-tuned on a real dataset with CTC loss.
The model was trained with python=3.11.0, pytorch=2.1.0, cuda=11.8 and builds on the DETR-variants DINO/DN/DAB and Deformable-DETR.
pip install -r requirements.txt
python models/dino/ops/setup.py build install # 'cuda not available', run => export CUDA_HOME=/usr/local/cuda-<version>
# unit test (should see all checking is True) # could output an outofmemory error
python models/dino/ops/test.py
Datasets should be placed in the appropriate folder specified in datasets/config.json. We preprocess the images and annotations for the IAM dataset, while all other datasets are used in their original form. For each dataset (except IAM), a charset file (.pkl) is required. Charset files can be found in the folder data.
Handwritten
Chinese The official website is here. Images and annotations are provide only in bytes format for these datasets.
Ciphers The ciphers borg and copiale are available here. The charset files are provided in the folder data.
Pretrained checkpoints can be found here. The folder includes the weights of the following pretrained models:
Finetuned checkpoints can be found here.
Checkpoints should be organized as follows:
logs/
└── IAM/
└── checkpoint.pth
└── other_model/
└── checkpoint.pth
...
Pretraining scipts are available in scripts/pretraining.
You need to download the folder resources (background, fonts, noises, texts) and place it in the folder dataset.
To train models with random erasing:
sh scripts/pretraining/Synthetic_english_w_masking.sh
sh scripts/pretraining/Synthetic_german_w_masking.sh
sh scripts/pretraining/Synthetic_french_w_masking.sh
sh scripts/pretraining/Synthetic_general.sh
You need the dataset CASIA v1 [here]
To train a model with random erasing
sh scripts/pretraining/Synthetic_english.sh
Then for instances to train a model for chinese with random erasing:
bash scripts/pretraining/Synthetic_chinese_w_masking.sh
Finetuning occurs in two stages. The scripts are available in scripts/finetuning.. For Step 1 it is expected that a model is pretrained is placed in the folder logs/your_model_name.
Use the scripts in scripts/evaluating to evaluate the model on the different datasets.
We provide our N-gran models for RIMES, READ and IAM here. We strongly advice to create a separate environment for the ngram model and to install the libraries in the ngram/mini_guide.md. To run an evalutation with the ngram model:
bash python ngram/clean_gen_ngram_preds.py --config_path ngram/IAM.yaml
bash python ngram/clean_gen_ngram_preds.py --config_path ngram/READ.yaml
bash python ngram/clean_gen_ngram_preds.py --config_path ngram/RIMES.yaml
To train you own ngram model, follow the instructions in the ngram/mini_guide.md
If you find this code useful, don't forget to star the repo :star: and cite the papers :point_down:
@article{baena2024DTLR, title={General Detection-based Text Line Recognition},
author={Raphael Baena and Syrine Kalleli and Mathieu Aubry},
booktitle={NeurIPS},
year={2024}},
url={https://arxiv.org/abs/2409.17095},
29 commits
7 commits
Python
53.5%
Jupyter Notebook
39.8%
Cuda
5.3%