Optical Character Recognition made seamless & accessible to anyone, powered by PyTorch

This is the open-source version of the layout detection model. For a more powerful version, get in contact with t2k GmbH.

For more information, see the docTR repository

Standalone usage

import numpy as np
from doctr.models import layout_predictor
 
model = layout_predictor("lw_detr_s", pretrained=True)
dummy_img = (255 * np.random.rand(800, 600, 3)).astype(np.uint8)
out = model([dummy_img])
# out[0] -> {"class_names": ["Title", "Text", ...], "boxes": array(...), "scores": array(...)}

Usage inside the OCR pipeline

from doctr.io import DocumentFile
from doctr.models import ocr_predictor
 
model = ocr_predictor(pretrained=True, detect_layout=True, layout_arch="lw_detr_s")
doc = DocumentFile.from_images("path/to/your/doc.jpg")
result = model(doc)
 
# Access the detected layout regions of the first page
for region in result.pages[0].layout:
    print(region.type, region.confidence, region.geometry)
# Title 0.97 ((0.13, 0.06), (0.87, 0.11))
# Text 0.95 ((0.11, 0.14), (0.89, 0.42))
# Table 0.93 ((0.12, 0.45), (0.88, 0.79))
 
# The layout is part of the exported representation
export = result.pages[0].export()
print(export["layout"])
 
# Overlay both text and layout regions (use display_layout=False to hide the regions)
result.pages[0].show()

Stats

  • Model Size: ~ 15.1M parameters (~ 60 MB footprint)
  • Reference Latency: ~0.5s / page on standard server CPU
Metric text2knowledge/doctr-torch-lw-detr-s-open
AP@50 (IoU Threshold 0.50) 82.83 %
AP@75 (IoU Threshold 0.75) 73.75 %
mAP@[.5:.95] 66.89 %

Hardware Benchmarks CPU vs. GPU

Metric CPU Execution GPU Execution (NVIDIA RTX 5070 Laptop) Speedup / Delta
Device Platform CPU (x86_64) CUDA (NVIDIA GeForce RTX 5070 Laptop GPU) โ€”
Model Load Time 2.16 ms 157.24 ms CPU ~72x faster load
Mean Inference Time 12.212 s 0.883 s ~14x faster on GPU
Per-Page Latency (Avg) 0.872 s / page 0.063 s / page ~14x faster on GPU
Throughput 1.15 pages/s 15.85 pages/s ~14x higher throughput on GPU
Min Total Runtime 11.471 s 0.867 s โ€”
Max Total Runtime 12.444 s 0.938 s โ€”
Standard Deviation 0.294 s 0.027 s Higher stability on GPU
Downloads last month
25
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support