NeuralNetworkArchitecture<T>

Models & Types · AiDotNet.NeuralNetworks

Defines the structure and configuration of a neural network, including its layers, input/output dimensions, and task-specific properties.

Known derived types: CodeSynthesisArchitecture<T>, DualEncoderArchitecture<T>, TransformerArchitecture<T>, TripleStreamArchitecture<T>

For Beginners

Think of NeuralNetworkArchitecture as the blueprint for building a neural network.

Just like an architect’s blueprint for a building specifies:

  • How many floors the building will have
  • The size and purpose of each room
  • How rooms connect to each other

The NeuralNetworkArchitecture defines:

  • What kind of data your network will process (like images or text)
  • How many layers your network will have
  • How many neurons are in each layer
  • How the layers connect to process your data

Before you can build a neural network, you need this blueprint to ensure all the parts will fit together correctly. It helps prevent errors like trying to feed image data into a network designed for text, or having layers that don’t match up in size.

How It Works

The NeuralNetworkArchitecture class serves as a blueprint for constructing neural networks with specific configurations. It handles the validation of input dimensions, layer compatibility, and provides methods for retrieving information about the network’s structure. This architecture can be used to create various types of neural networks with different input dimensionalities and layer arrangements.

Constructors

Constructor Summary
NeuralNetworkArchitecture(InputType inputType, NeuralNetworkTaskType taskType, NetworkComplexity complexity, int inputSize, int inputHeight, int inputWidth, int inputDepth, int outputSize, List<ILayer<T>> layers, bool shouldReturnFullSequence, int imageEmbeddingDim, int textEmbeddingDim, int inputFrames) Initializes a new instance of the NeuralNetworkArchitecture class with the specified parameters.
NeuralNetworkArchitecture(int inputFeatures, int numClasses, bool isMultiClass, NetworkComplexity complexity) Initializes a new instance of the NeuralNetworkArchitecture class for classification tasks.
NeuralNetworkArchitecture(int inputFeatures, int outputSize, NetworkComplexity complexity) Initializes a new instance of the NeuralNetworkArchitecture class for regression tasks.

Properties

Property Summary
InputType InputType { get; } Gets the type of input the neural network is designed to handle.
List<ILayer<T>> Layers { get; } Gets the optional list of predefined layers for the neural network.
NetworkComplexity Complexity { get; } Gets the complexity level of the neural network.
NeuralNetworkTaskType TaskType { get; } Gets the type of task the neural network is designed to perform.
bool HasDynamicSpatialDims { get; } Indicates whether this architecture declares dynamic (lazy) spatial dimensions — InputHeight and InputWidth set to -1 as PyTorch-style sentinels, meaning the network resolves H/W from the actual input on the first forward.
bool IsInitialized { get; set; } Gets a value indicating whether the architecture has been initialized.
bool IsLayerOnly { get; set; } True when this architecture is a CreateLayerOnly stub — a placeholder used by sub-modules / lazy backbones that don’t carry a semantic input contract.
bool ShouldReturnFullSequence { get; } Determines whether the network should return the full sequence or just the final output.
bool UseAutodiff { get; set; } Gets or sets a value indicating whether all layers in this architecture should use automatic differentiation by default.
int CalculatedInputSize { get; } Gets the calculated total size of the input based on dimensions.
int ImageEmbeddingDim { get; } Gets the dimensionality of image embeddings for multimodal networks.
int InputDepth { get; } Gets the depth dimension for 3D inputs.
int InputDimension { get; } Gets the dimensionality of the input (1, 2, or 3).
int InputFrames { get; set; } Gets the frame-count dimension for 4D (temporal video) inputs.
int InputHeight { get; set; } Gets the height dimension for 2D or 3D inputs.
int InputSize { get; set; } Gets or sets the size of the input vector.
int InputWidth { get; set; } Gets the width dimension for 2D or 3D inputs.
int OutputSize { get; } Gets the size of the output vector.
int TextEmbeddingDim { get; } Gets the dimensionality of text embeddings for multimodal networks.
int? DefaultRandomSeedOverride { get; set; } Process-wide fallback for RandomSeed when no explicit per-architecture seed was set.
int? RandomSeed { get; set; } Optional seed for reproducible weight initialization across all layers in this architecture.

Methods

Method Summary
NeuralNetworkArchitecture<T> CreateDynamicSpatial(InputType inputType, NeuralNetworkTaskType taskType, int channels, int outputSize, int frames) Creates an architecture for a network whose spatial dimensions are resolved on the first forward pass (PyTorch LazyConv2d-style).
NeuralNetworkArchitecture<T> CreateLayerOnly() Creates a “layer-only” architecture stub for sub-modules and detection backbones whose input contract is owned by a parent network.
int CalculateOutputSize() Calculates the total size of the output.
int[] GetHiddenLayerSizes() Gets the sizes of the hidden layers in the neural network.
int[] GetInputShape() Gets the shape of the input as an array of dimensions.
int[] GetLayerSizes() Gets the size of each layer in the neural network.
int[] GetOutputShape() Gets the shape of the output as an array of dimensions.
void InitializeFromCachedData() Initializes the architecture from cached data.