Table of Contents

Class DeserializationHelper

Namespace
AiDotNet.Helpers
Assembly
AiDotNet.dll
public static class DeserializationHelper
Inheritance
DeserializationHelper
Inherited Members

Methods

CreateLayerFromType<T>(string, int[], int[], Dictionary<string, object>?)

Creates a layer of the specified type during deserialization.

public static ILayer<T> CreateLayerFromType<T>(string layerType, int[] inputShape, int[] outputShape, Dictionary<string, object>? additionalParams = null)

Parameters

layerType string

The type name of the layer to create.

inputShape int[]

The input shape of the layer.

outputShape int[]

The output shape of the layer.

additionalParams Dictionary<string, object>

Additional parameters needed for layer creation.

Returns

ILayer<T>

A new layer instance of the specified type.

Type Parameters

T

The numeric type used in the neural network.

Remarks

This method creates a new layer instance based on its type name and the specified input and output shapes. It uses reflection to dynamically create instances of layer types, allowing for easy addition of new layer types. Additional parameters can be provided for layers that require more information during instantiation.

For Beginners: This method is like a factory that can create any type of layer in our network.

When loading a saved network:

  • We need to recreate each layer with the correct settings
  • This method looks up how to create each type of layer
  • It sets up the layer with the right input and output sizes
  • For some layers, it uses extra information to set them up correctly

This design makes it easy to add new types of layers in the future without changing this method.

DeserializeInterface<TInterface>(BinaryReader)

Deserializes and creates an instance of an interface based on the type name read from a BinaryReader.

public static TInterface? DeserializeInterface<TInterface>(BinaryReader reader) where TInterface : class

Parameters

reader BinaryReader

The BinaryReader to read the type name from.

Returns

TInterface

An instance of the deserialized interface, or null if no type name was provided.

Type Parameters

TInterface

The interface type to deserialize.

Exceptions

InvalidOperationException

Thrown when the type cannot be found or instantiated.