Docs /Templates/ sinapsis-doctr

DocTROCRPrediction

sinapsis-doctrOCRoptical_character_recognitionimagedoctrtext

Python template · sinapsis_doctr.templates.doc_tr_ocr_prediction

Overview

Template for Optical Character Recognition (OCR) prediction using docTR.

This class leverages docTR's OCR models to extract text, bounding boxes, and confidence scores from images. The extracted information is stored as annotations to each image packet in the input DataContainer.

docTR uses a two-stage approach for OCR: 1. Text detection: Localizing words in the document 2. Text recognition: Identifying characters in each detected word

The template allows configuration of both detection and recognition architectures, as well as various processing options.

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-doctr==1.0.0
uv pip install sinapsis-doctr==1.0.0
uv add sinapsis-doctr==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

det_arch

Detection architecture to use. Defaults to "fast_base". Options include db_resnet50, linknet_resnet18, fast_base, etc.

typing.Literal['db_resnet34', 'db_resnet50', 'db_mobilenet_v3_large', 'linknet_resnet18', 'linknet_resnet34', 'linknet_resnet50fast_tiny', 'fast_small', 'fast_base']
Optional
Default: "fast_base"
metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
reco_arch

Recognition architecture to use. Defaults to "crnn_vgg16_bn". Options include crnn_vgg16_bn, master, parseq, etc.

typing.Literal['crnn_vgg16_bn', 'crnn_mobilenet_v3_small', 'crnn_mobilenet_v3_large', 'master', 'sar_resnet31', 'vitstr_small', 'vitstr_base', 'parseq']
Optional
Default: "crnn_vgg16_bn"
pretrained

Whether to use pretrained models. Defaults to True.

bool
Optional
Default: true
symmetric_pad

Whether to use symmetric padding. Defaults to True.

bool
Optional
Default: true
detect_language

Whether to detect language of the text. Defaults to False.

bool
Optional
Default: false
straighten_pages

Whether to straighten pages before processing. Defaults to False.

bool
Optional
Default: false
detect_orientation

Whether to detect page orientation. Defaults to False.

bool
Optional
Default: false
pretrained_backbone

Whether to use pretrained backbones. Defaults to True.

bool
Optional
Default: true
assume_straight_pages

Whether to assume pages are straight (not rotated). Defaults to True.

bool
Optional
Default: true
preserve_aspect_ratio

Whether to preserve aspect ratio during preprocessing. Defaults to True.

bool
Optional
Default: true
artefact_type_as_labels

Whether to use artefact types as label strings. Defaults to False.

bool
Optional
Default: false
export_as_straight_boxes

Whether to export rotated boxes as straight boxes. Defaults to False.

bool
Optional
Default: false
recognized_characters_as_labels

Whether to use recognized text as label strings. Defaults to False.

bool
Optional
Default: false

Configuration example

Generated from documented defaults. Replace any placeholders and complete required nested settings before running.

yaml
templates:
  - template_name: "DocTROCRPrediction"
    class_name: "DocTROCRPrediction"
    attributes:
      det_arch: "fast_base"
      reco_arch: "crnn_vgg16_bn"
      pretrained: true
      symmetric_pad: true
      detect_language: false
      straighten_pages: false
      detect_orientation: false
      pretrained_backbone: true
      assume_straight_pages: true
      preserve_aspect_ratio: true
      artefact_type_as_labels: false
      export_as_straight_boxes: false
      recognized_characters_as_labels: false

Inheritance

Immediate parent: sinapsis_core.template_base.template.Template

Environment variables

Environment definitions belong to their canonical Python modules.

No directly related environment variables listed.