LayoutGraph<T>

Models & Types · AiDotNet.Document.GraphBased

LayoutGraph: graph-based document layout analysis after GLAM (Wang et al. 2023).

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

Implements: ILayoutDetector<T>, IReadingOrderDetector<T>

For Beginners

LayoutGraph analyzes how document parts relate:

  1. Builds a graph from document structure
  2. Models reading order and containment
  3. Learns hierarchical relationships
  4. Predicts document element types and groupings

Key features:

  • Hierarchical graph construction
  • Spatial relationship modeling
  • Reading order prediction
  • Multi-level layout understanding

Example usage:

How It Works

LayoutGraph constructs and analyzes graphs from document layouts, where nodes represent document elements and edges encode spatial relationships: as in GLAM, a node-feature input [N, F] whose first four columns are each element’s normalized box is joined into a k-nearest-centre page graph, graph convolutions propagate over it, and each node is classified with a softmax. It excels at understanding hierarchical document structures.

Constructors

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

Properties

Property Summary
DocumentType SupportedDocumentTypes { get; }
IReadOnlyList<LayoutElementType> SupportedElementTypes { get; }
bool RequiresOCR { get; }
int ExpectedImageSize { get; }
int NodeDim { get; } Gets the node dimension.

Methods

Method Summary
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input)
DocumentLayoutResult<T> DetectLayout(Tensor<T> documentImage)
DocumentLayoutResult<T> DetectLayout(Tensor<T> documentImage, double confidenceThreshold)
ModelMetadata<T> GetModelMetadata()
ReadingOrderResult<T> DetectReadingOrder(DocumentLayoutResult<T> layoutResult)
ReadingOrderResult<T> DetectReadingOrder(Tensor<T> documentImage)
Tensor<T> EncodeDocument(Tensor<T> documentImage)
Tensor<T> ForwardForTraining(Tensor<T> input) Training forward: runs the base training forward (which wires layer seeds and applies gradient checkpointing / weight streaming over the graph layers), then mean-pools every axis but the class axis so the per-node logits [numNodes, numClas…
string GetModelSummary()
void ValidateInputShape(Tensor<T> documentImage)