Skip to main content

Docling metrics for document layout analysis

Overview

The following metrics are used:

  • Mean Average Precision.
  • pixel-wise multi-label confusion matrix.

Installation

uv sync --all-packages

Usage

import logging
from pathlib import Path

from docling_metrics_layout import (
    LayoutMetrics,
    LayoutMetricSample,
)
from docling_metrics_layout.layout_types import LayoutMetricDatasetEvaluation

# Data
DATA = {
    "id": "page_001",
    "page_width": 612,
    "page_height": 792,
    "page_resolution_a": [
        {"category_id": 1, "bbox": [50.0, 80.0, 300.0, 200.0], "score": 0.97},
        {"category_id": 2, "bbox": [310.0, 80.0, 560.0, 200.0], "score": 0.91},
        {"category_id": 1, "bbox": [50.0, 220.0, 560.0, 380.0], "score": 0.88},
        {"category_id": 3, "bbox": [50.0, 400.0, 300.0, 500.0], "score": 0.76},
    ],
    "page_resolution_b": [
        {"category_id": 1, "bbox": [52.0, 82.0, 298.0, 202.0], "score": 0.95},
        {"category_id": 2, "bbox": [312.0, 78.0, 558.0, 199.0], "score": 0.89},
        {"category_id": 1, "bbox": [48.0, 218.0, 562.0, 382.0], "score": 0.85},
    ],
}

CATEGORIES = {1: "red", 2: "orange", 3: "green", 4: "blue"}

REPORT_DIR = "reports/"


def setup_logging():
    log_format = "%(asctime)s - %(levelname)s - %(message)s"
    logging.basicConfig(level=logging.INFO, format=log_format)


def demo():
    # Load the data as list[LayoutMetricSample]
    samples = [LayoutMetricSample.model_validate(DATA)]

    # Evaluate
    lm = LayoutMetrics(CATEGORIES, save_root=Path(REPORT_DIR))
    evaluation: LayoutMetricDatasetEvaluation = lm.evaluate_dataset(samples)

    # mAP metrics
    map_eval = evaluation.dataset_map_layout_evaluation
    print(f"\nmAP:         {map_eval.map:.4f}")
    print(f"mAP per class: {map_eval.map_per_class}")

    # TORE metrics
    tore_matrix = evaluation.dataset_tore_evaluation.matrix_evaluation.detailed
    print(f"\nPrecision matrix:\n{tore_matrix.precision_matrix}")
    print(f"\nRecall matrix:\n{tore_matrix.recall_matrix}")

    # Report files
    print("\nReport files:")
    for f in evaluation.reports:
        print(f"  {f.name}")


if __name__ == "__main__":
    setup_logging()
    demo()

Multi-Label Classifier Performance Evaluation with Confusion Matrix

License

MIT

Metadata

Release files for docling-metrics-layout 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docling-metrics-layout 0.17.0
File Size Uploaded Provenance Actions
docling_metrics_layout-0.17.0.tar.gz 34.3 kB With provenance Details for docling_metrics_layout-0.17.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for docling-metrics-layout 0.17.0
File Interpreter ABI Platform Actions
docling_metrics_layout-0.17.0-py3-none-any.whl Python 3 none any Details for docling_metrics_layout-0.17.0-py3-none-any.whl

Total release size: 59.6 kB

Release files / docling_metrics_layout-0.17.0.tar.gz

Download URL docling_metrics_layout-0.17.0.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9d42bb8b114fbb5fe4a80d1705c5ae0c9574db20579103d16c5d4a8c0a17867a
BLAKE2b-256 checksum
How to use checksums
21a035624f871e746d8a68cea712be8c644c39a86be1c997ceb8dad9863a4d8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / docling_metrics_layout-0.17.0-py3-none-any.whl

Download URL docling_metrics_layout-0.17.0-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa106a210b36c91077b15847fc6fef1e35c70d93eb1656321922333a465da00c
BLAKE2b-256 checksum
How to use checksums
ade0066c14b4d361041a0e17caa1724988c2b08c7876e69712bdfd7794d47c8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Security for docling-metrics-layout 0.17.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for docling_metrics_layout-0.17.0.tar.gz

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 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page