D-FINE for document layout analysis
This is an adaptation//refactor of ArgoHA's implementation of the D-FINE object detector intended to put it in line with community standards in the (historical) document layout analysis community. It is a foundation for eventual integration into the kraken ATR engine.
Installation
Kraken is currently being rewritten to allow integration of new methods, such as the one in this repository, with plug-ins. This repository uses the architecture introduced by this rework which will eventually become kraken 7.0. The models produced by this repository are not going to be compatible with earlier kraken versions.
For the latest stable release run:
$ pip install dfine_kraken
Clone the repository and run:
$ pip install .
This will install a dfine that can be used to train models:
$ dfine ... train ...
Training
The basic syntax is very similar to kraken segmentation training using Page or ALTO XML files. During the rework many of the segmentation dataset filtering and transformation options have disappeared, being replaced by dictionaries mapping class labels to indices. As it is annoying to define mapping on the command line, mappings that do not assign one index to each class in the source data need to be defined in YAML experiment configuration files.
To train a basic model for 50 epochs from scratch:
$ dfine -d cuda:0 train *.xml
The default configuration trains lines and regions jointly. If this is not what you want take a look at the sample configuration file to see how to disable text line detection in bbox format.
Inference
Inference is integrated in kraken. You need to convert the checkpoint into weights first:
$ ketos convert -o dfine.safetensors checkpoint.ckpt
and then run kraken ... segment ... as usual:
$ kraken -i input.jpg out.xml -a segment -i dfine.safetensors
Pretrained Models
Pretrained region segmentation models trained on the
LADaS dataset using the
SegmOnto taxonomy (37 region types) are
available for all model variants. They can be downloaded with kraken download:
| Variant | Size | mAP@50 | Download command |
|---|---|---|---|
| nano | ~15 MB | 0.2960 | kraken get 10.5281/zenodo.18715384 |
| small | ~42 MB | 0.3864 | kraken get 10.5281/zenodo.18715381 |
| medium | ~79 MB | 0.3915 | kraken get 10.5281/zenodo.18715373 |
| large | ~126 MB | 0.4308 | kraken get 10.5281/zenodo.18715364 |
| extra_large | ~252 MB | 0.4164 | kraken get 10.5281/zenodo.18715367 |
The large variant achieves the best performance. The extra_large variant shows slight regression likely due to overfitting, so the large model is recommended for best accuracy.
$ kraken get 10.5281/zenodo.18715373
Processing ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 79.1/79.1 MB 0:00:00 0:00:02
Model dir: /home/mittagessen/.local/share/htrmopo/d58d541d-82cf-5ab2-b27b-a20fe2548229 (model files: ladas_m.safetensors)
$ kraken -i input.jpg out.xml -a segment -i ladas_m.safetensors
...
Metadata
Release files for dfine-kraken 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dfine_kraken-0.4.4.tar.gz | 55.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dfine_kraken-0.4.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 121.8 kB
Release files / dfine_kraken-0.4.4.tar.gz
| Download URL | dfine_kraken-0.4.4.tar.gz |
|---|---|
| Size | 55.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5a22f4e0c00c80298c42391c9d712a058b6e2de489bdba2d5c41cde15460e16
|
|
BLAKE2b-256 checksum How to use checksums |
069dca2abea671f235b3d4fb79be1db857e573db425c8d5725aa93ddb25d9562
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / dfine_kraken-0.4.4-py3-none-any.whl
| Download URL | dfine_kraken-0.4.4-py3-none-any.whl |
|---|---|
| Size | 66.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c234d4534c1665166047e4f733d4f015957c3deccc408720162aebe5f35db15c
|
|
BLAKE2b-256 checksum How to use checksums |
a5e355e5f6069cba47b710fb0fbca03f323727fee1dc7a9038ba01ddcbc2fe69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency log