Document Text Recognition: open source OCR powered by PyTorch
open sourceApache-2.0self-hostablefree
docTR (Document Text Recognition) is an open source Python OCR library that reads PDFs and images and returns every word with its position, organised into lines, blocks, layout regions and tables. OCR runs in two stages: a text detection model (DBNet, LinkNet or FAST) finds the words and a recognition model (CRNN, SAR, MASTER, ViTSTR, PARSeq or VIPTR) reads each one, and optional models add layout analysis, table structure, formula recognition and page and word orientation for skewed or upside-down scans. Results export to JSON, Markdown, HTML, AsciiDoc and hOCR, models can be fine-tuned and shared on the Hugging Face Hub, and it deploys with ONNX export, Docker images and a FastAPI template. Mindee created it; t2k GmbH now develops and maintains it, under Apache-2.0.
Problems it solves
- extract the text from scanned PDFs and phone photos of documents in Python, with word positions
- get bounding boxes for every word on a page so I can map text back to where it sits on the form
- self-hosted OCR on my own servers because documents can't go to a cloud API
- OCR that copes with pages scanned sideways or upside down
- turn a table in a scanned document into rows and columns I can load into pandas
- find titles, paragraphs, headers and footers on a scanned page before extracting its text
- fine-tune an OCR model on my own documents and fonts
- deep learning OCR in Python with an Apache licence I can ship commercially
- export OCR results as hOCR or Markdown in proper reading order across columns
- run OCR inference faster on CPU by exporting the models to ONNX
- pull specific fields like dates and addresses out of documents with a multi-class text detector
- stand up an internal OCR REST API in a Docker container
- train a recognition model for an alphabet the stock OCR models don't read
Features
- reads PDFs, images and web pages (with WeasyPrint)
- two-stage OCR: 3 detection families (DBNet, LinkNet, FAST) and 6 recognition families (CRNN, SAR, MASTER, ViTSTR, PARSeq, VIPTR)
- pretrained models selected with det_arch and reco_arch
- layout analysis with LW-DETR (detect_layout=True)
- table structure recognition with TableCenterNet, exportable to a row and column grid
- formula recognition with FormulaNet
- page and word-crop orientation classifiers, straighten_pages and rotated bounding boxes
- document tree of pages, blocks, lines and words with geometry and confidence
- export to JSON, plain text, Markdown, AsciiDoc, HTML and hOCR in reading order
- KIE predictor for multi-class detection of fields such as dates and addresses
View 6 more
- character whitelists and 100+ built-in vocabularies for training
- reference training scripts and sharing models on the Hugging Face Hub
- ONNX export and the OnnxTR runtime
- GPU and half precision, torch.compile
- GPU-ready Docker images, a CLI analysis script and a FastAPI REST API template
- Streamlit demo app and a live demo on Hugging Face Spaces
Limitations
- Pretrained models don't read non-Latin scripts: they're trained on a French vocabulary (Western European accents); other languages need a community model or training1
Capabilities
| Has official SDKs | plan not known |
|---|
Alternatives
The same job
These do what docTR does.
- OCRmyPDF Adds a searchable OCR text layer to scanned PDFs
- Docling Get your documents ready for gen AI
- PaddleOCR Turn any PDF or image document into structured data for your AI
- Mistral OCR Mistral AI's document OCR model and API: PDFs and images to structured Markdown, priced per page
- Surya OCR, layout analysis, reading order and table recognition in 90+ languages
- EasyOCR Ready-to-use OCR with 80+ supported languages and all popular writing scripts