TrOCROptions<T>

Options & Configuration · AiDotNet.ComputerVision.OCR.Recognition

TrOCR’s architecture hyperparameters. The defaults are TrOCR-Base (Li et al. 2023, Table 1): a BEiT-Base image encoder and a RoBERTa-Large-sized text decoder.

Inheritance: OCROptions<T> → TrOCROptions<T>

How It Works

The encoder and decoder have different widths in every published TrOCR size, so each is configured on its own. When they differ, the encoder output is projected to the decoder width before cross-attention, as HuggingFace’s VisionEncoderDecoderModel does with enc_to_dec_proj.

Constructors

Constructor Summary
TrOCROptions() Creates TrOCR-Base options.

Properties

Property Summary
int DecoderHeads { get; set; } Text-decoder attention heads (TrOCR-Base: 16).
int DecoderHiddenDim { get; set; } Text-decoder width (TrOCR-Base: 1024).
int DecoderLayers { get; set; } Text-decoder layers (TrOCR-Base: 12).
int EncoderHeads { get; set; } Image-encoder attention heads (BEiT-Base: 12).
int EncoderHiddenDim { get; set; } Image-encoder width (BEiT-Base: 768).
int EncoderLayers { get; set; } Image-encoder layers (BEiT-Base: 12).
int PatchSize { get; set; } Square image-patch side in pixels (16).

Methods

Method Summary
void Validate() Throws when a size cannot build a working TrOCR: a non-positive width, head count, patch size or layer count, or a width the head count does not divide (attention would split it into mismatched heads).