docTR: Document Text Recognition#
OCR made seamless & accessible to anyone
docTR reads PDFs and images and gives you back every word with its position, organized into lines, blocks, layout regions and tables. Run state-of-the-art models in three lines of Python, fine-tune them on your own documents and ship them anywhere.
from doctr.io import DocumentFile from doctr.models import ocr_predictor model = ocr_predictor(pretrained=True) doc = DocumentFile.from_pdf("invoice.pdf") result = model(doc) # or export to JSON, Markdown, HTML... print(result.render())
Everything you need to read documents
From a scanned receipt to a hundred-page report: docTR covers the whole pipeline, and every stage can be swapped, tuned or retrained.
A text detection model finds the words, a recognition model reads them. Mix and match 9 detection and 9 recognition architectures.
Detect titles, paragraphs, figures and tables, and turn tables into a row/column grid that loads straight into pandas.
Handle skewed scans, upside-down pages and vertical text with built-in page and word orientation classifiers.
Get plain text, JSON, Markdown, AsciiDoc, HTML or hOCR, in a reading order that follows columns, headers and footers.
Fine-tune any model on your own data with the reference training scripts, then share it on the Hugging Face Hub.
GPU & half precision, torch.compile, ONNX export, Docker images, a CLI and a REST API template.
How it works
An OCR predictor chains specialized models. Each stage is a regular PyTorch module you can replace with your own.
Find your way around
Whether you need text out of a PDF in five minutes or want to train a model for a new alphabet, start here.
Install docTR and extract the text of your first document in five minutes.
Load documents, configure the OCR predictor, navigate and export the results.
All architectures with their benchmarks, to pick the right speed/accuracy trade-off.
Datasets, data formats, training scripts and how to load your own checkpoints.
Speed up inference, export to ONNX, and serve docTR with Docker or a REST API.
Every public class and function, generated from the source code.
Need help with a complex use case?
docTR was created by Mindee and is developed and maintained by t2k GmbH, who offer custom development, integration and consulting around docTR.