Class FromFileInitializationStrategy<T>
- Namespace
- AiDotNet.Initialization
- Assembly
- AiDotNet.dll
Initialization strategy that loads weights from an external file.
public class FromFileInitializationStrategy<T> : InitializationStrategyBase<T>, IInitializationStrategy<T>
Type Parameters
TThe numeric type used for calculations.
- Inheritance
-
FromFileInitializationStrategy<T>
- Implements
- Inherited Members
Remarks
This strategy loads pre-trained weights from a file, enabling transfer learning and model checkpointing. Weights are loaded during the first initialization call and cached for subsequent layers.
For Beginners: Transfer learning is like giving your network a head start by using weights that were already trained on a similar task. Instead of starting from random values, you start with values that already know useful patterns.
Supported formats: - JSON: Human-readable format with weight arrays - Binary: Compact binary format for faster loading
Constructors
FromFileInitializationStrategy(string, WeightFileFormat)
Initializes a new instance of the FromFileInitializationStrategy<T> class.
public FromFileInitializationStrategy(string filePath, WeightFileFormat format = WeightFileFormat.Auto)
Parameters
filePathstringThe path to the weights file.
formatWeightFileFormatThe format of the weights file. Default is Auto-detect.
Properties
IsLazy
Gets a value indicating whether this strategy defers initialization until first use.
public override bool IsLazy { get; }
Property Value
- bool
trueif initialization is deferred until first Forward() call;falseif initialization happens immediately.
LoadFromExternal
Gets a value indicating whether weights should be loaded from an external source.
public override bool LoadFromExternal { get; }
Property Value
- bool
trueif weights should be loaded from file or other external source;falseif weights should be randomly initialized.
Methods
ClearCache()
Clears the cached weights, forcing a reload on next initialization.
public void ClearCache()
Remarks
This method is thread-safe. All cached data is cleared atomically.
InitializeBiases(Tensor<T>)
Initializes the biases tensor with appropriate values.
public override void InitializeBiases(Tensor<T> biases)
Parameters
biasesTensor<T>The biases tensor to initialize.
InitializeWeights(Tensor<T>, int, int)
Initializes the weights tensor with appropriate values.
public override void InitializeWeights(Tensor<T> weights, int inputSize, int outputSize)
Parameters
weightsTensor<T>The weights tensor to initialize.
inputSizeintThe number of input features.
outputSizeintThe number of output features.
Reset()
Resets the layer indices for a fresh initialization pass.
public void Reset()
Remarks
Call this method if you need to re-initialize a network with the same weights. This method is thread-safe.