StackMap
Subscribe
Explore / doctr
mindee

doctr

docTR: two-stage OCR in PyTorch — detect words, then recognize them — with pretrained detection and recognition architectures you can mix, plus layout detection and rotated-page handling.

6,306 672 Python Apache-2.0updated 3 days ago
View on GitHubDispute this mapping →
Curator's take

The dependable choice when you want OCR as a library rather than a model to serve: pick a detector and a recognizer, call `ocr_predictor(pretrained=True)`, get word-level boxes and text from PDFs or images, with rotated-page handling and optional layout regions. It predates the VLM wave and that's the point — small models, no prompt, deterministic output, trainable on your own data, and cheap enough to run per-page at volume. Two caveats: it gives you words and boxes, not document structure, so reading order, tables and markdown are your job (pair it with a parser); and stewardship moved from Mindee to t2k GmbH, so check commit cadence against the newer VLM OCR crowd before standardizing on it.

Mapped by ShipWithAI editors · links verified
README.md

Slack Icon License Build Status Docker Images codecov CodeFactor Codacy Badge Doc Status Pypi Hugging Face Spaces Open In Colab Gurubase

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

Project responsibility

docTR was originally created by Mindee. It is now actively developed and maintained by t2k GmbH.

Need help solving a complex use case?

What you can expect from this repository:

  • efficient ways to parse textual information (localize and identify each word) from your documents
  • guidance on how to integrate this in your current architecture

OCR_example

Quick Tour

Getting your pretrained model

End-to-End OCR is achieved in docTR using a two-stage approach: text detection (localizing words), then text recognition (identify all characters in the word). As such, you can select the architecture used for text detection, and the one for text recognition from the list of available implementations.

from doctr.models import ocr_predictor

model = ocr_predictor(det_arch="db_resnet50", reco_arch="crnn_vgg16_bn", pretrained=True)

Reading files

Documents can be interpreted from PDF or images:

from doctr.io import DocumentFile

# PDF
pdf_doc = DocumentFile.from_pdf("path/to/your/doc.pdf")
# Image
single_img_doc = DocumentFile.from_images("path/to/your/img.jpg")
# Webpage (requires `weasyprint` to be installed)
webpage_doc = DocumentFile.from_url("https://www.yoursite.com")
# Multiple page images
multi_img_doc = DocumentFile.from_images(["path/to/page1.jpg", "path/to/page2.jpg"])

Putting it together

Let's use the default pretrained model for an example:

from doctr.io import DocumentFile
from doctr.models import ocr_predictor

model = ocr_predictor(pretrained=True)
# PDF
doc = DocumentFile.from_pdf("path/to/your/doc.pdf")
# Analyze
result = model(doc)

Detecting the document layout

You can additionally run a layout detection model as part of

Continue your stack

What teams reach for next — and why each earns a place beside doctr. Ranked by curator confidence.