SVTR<T>

Models & Types · AiDotNet.Document.OCR.TextRecognition

SVTR (Scene Text Visual Transformer) for text recognition.

Inheritance: NeuralNetworkBase<T> → DocumentNeuralNetworkBase<T> → SVTR<T>

Implements: IPaperOptimizerVariant, ITextRecognizer<T>

For Beginners

SVTR modernizes text recognition:

  1. Uses vision transformer (no RNN needed)
  2. Handles various text heights and lengths
  3. Multi-scale feature extraction
  4. Efficient single-stream architecture

Key features:

  • Pure transformer architecture
  • Local + global mixing blocks
  • Height compression for efficiency
  • State-of-the-art accuracy

Example usage:

How It Works

SVTR is a single-stream vision transformer for scene text recognition that processes text images as visual sequences without requiring recurrent networks.

Reference: “SVTR: Scene Text Recognition with a Single Visual Model” (IJCAI 2022) https://arxiv.org/abs/2205.00159

Constructors

Constructor Summary
SVTR() Creates an SVTR model with default configuration for native training.
SVTR(NeuralNetworkArchitecture<T> architecture, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, SVTROptions options) Creates an SVTR model using native layers for training and inference.
SVTR(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, SVTROptions options) Creates an SVTR model using a pre-trained ONNX model for inference.

Properties

Property Summary
DocumentType SupportedDocumentTypes { get; }
bool RequiresOCR { get; }
bool SupportsAttentionVisualization { get; }
int ExpectedImageSize { get; }
int ImageHeight { get; } Gets the input image height.
int MaxSequenceLength { get; }
string PaperOptimizerVariant { get; }
string SupportedCharacters { get; }

Methods

Method Summary
IEnumerable<TextRecognitionResult<T>> RecognizeTextBatch(IEnumerable<Tensor<T>> croppedImages)
ModelMetadata<T> GetModelMetadata()
Tensor<T> EncodeDocument(Tensor<T> documentImage)
Tensor<T> ForwardForTraining(Tensor<T> input)
Tensor<T> GetAttentionWeights()
Tensor<T> GetCharacterProbabilities()
TextRecognitionResult<T> RecognizeText(Tensor<T> croppedImage)
string GetModelSummary()
void ValidateInputShape(Tensor<T> documentImage)