CoolFace
Modelpublic

text2knowledge/doctr-torch-lw-detr-s-open

sourceHugging Faceupdated 23d agoView on Hugging Face
0likes34downloads
Model Card

<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

python
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

python
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
Metrictext2knowledge/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
MetricCPU ExecutionGPU Execution (NVIDIA RTX 5070 Laptop)Speedup / Delta
Device PlatformCPU (x86_64)CUDA (NVIDIA GeForce RTX 5070 Laptop GPU)—
Model Load Time2.16 ms157.24 msCPU ~72x faster load
Mean Inference Time12.212 s0.883 s~14x faster on GPU
Per-Page Latency (Avg)0.872 s / page0.063 s / page~14x faster on GPU
Throughput`1.15 pages/s``15.85 pages/s`~14x higher throughput on GPU
Min Total Runtime11.471 s0.867 s—
Max Total Runtime12.444 s0.938 s—
Standard Deviation0.294 s0.027 sHigher stability on GPU