text2knowledge/doctr-torch-lw-detr-s-open
034
<p align="center"> <a href="https://www.text2knowledge.de/de"> <img src="https://github.com/mindee/doctr/raw/main/docs/images/doctr-need-help.png" width="60%"> </a> </p>
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
Hardware Benchmarks CPU vs. GPU
- Test Document: "Quantifying word complexity for Leichte Sprache: A computational metric and its psycholinguistic validation" (PDF paper, 14 pages)
- Test Protocol: 10 evaluation runs per hardware backend
- Host Platform: Linux 7.0.11-76070011-generic x86_64 (Python 3.11.15)
