LocallyConnectedLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Represents a Locally Connected layer which applies different filters to different regions of the input, unlike a convolutional layer which shares filters.
Inheritance: LayerBase<T> → LocallyConnectedLayer<T>
Implements: IShapeContract
For Beginners
This layer is like a specialized convolutional layer where each region gets its own unique filter.
Think of a Locally Connected layer like having specialized detectors for different regions:
- In a regular convolutional layer, the same filter slides across the entire input
- In a locally connected layer, each position has its own unique filter
- This means the layer can learn location-specific features
For example, in face recognition:
- A convolutional layer would use the same detector for eyes, whether looking at the top-left or bottom-right
- A locally connected layer would use different detectors depending on where it’s looking
This specialization increases the model’s power but:
- Requires more parameters
- May not generalize as well to new examples
- Is more computationally intensive
How It Works
The Locally Connected layer is similar to a convolutional layer in that it applies filters to local regions of the input, but differs in that it uses different filter weights for each spatial location. This increases the number of parameters and the expressiveness of the model, but reduces generalization capabilities. It’s useful when the patterns in different regions of the input are inherently different, such as in face recognition where different parts of a face have different characteristics.
Constructors
| Constructor | Summary |
|---|---|
LocallyConnectedLayer(int outputChannels, int kernelSize, int stride, IActivationFunction<T> activationFunction) |
Initializes a new instance of the LocallyConnectedLayer class with the specified dimensions, kernel parameters, and vector activation function. |
LocallyConnectedLayer(int outputChannels, int kernelSize, int stride, IVectorActivationFunction<T> vectorActivationFunction) |
Initializes a new instance of the LocallyConnectedLayer class with the specified dimensions, kernel parameters, and vector activation function. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetParameterRoles() |
Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases). |
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
void ClearGradients() |
|
void ResetState() |
Resets the internal state of the layer. |
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void UpdateParameters(T learningRate) |
Updates the parameters of the layer using the calculated gradients. |
void UpdateParametersGpu(IGpuOptimizerConfig config) |
Updates parameters using GPU-based optimizer. |
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |