NormedConv2DLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

A 2-D convolution with optional weight or spectral normalization, stride, padding and depthwise grouping — PyTorch’s Conv2d(...), weight_norm(Conv2d(...)) and spectral_norm(Conv2d(...)) as GAN encoders and discriminators use them.

Inheritance: LayerBase<T> → NormedConv2DLayer<T>

Implements: IShapeContract

For Beginners

An image-style convolution whose weights are kept at a controlled scale, which makes adversarial training more stable.

How It Works

The kernel V is initialized as PyTorch’s default (U(−1/√fan_in, 1/√fan_in) with fan_in the input channels per group times the kernel area), as is the bias. With weight normalization (Salimans and Kingma 2016) the kernel is W = g · V / ‖V‖ per output channel, g starting at ‖V‖. With spectral normalization (Miyato et al. 2018) the kernel is W = V / σ, σ = uᵀ V v over V reshaped to [out, in/groups · kh · kw]; u and v (persistent buffers, as in torch.nn.utils.spectral_norm) start from 15 power iterations, as PyTorch’s current spectral-norm parametrization starts, take one more on every training forward and stay fixed in evaluation. Groups are 1 or the channel count (a depthwise convolution). Input and output are [batch, channels, height, width].

Constructors

Constructor Summary
NormedConv2DLayer(int inChannels, int outChannels, int kernelHeight, int kernelWidth, int strideHeight, int strideWidth, int paddingHeight, int paddingWidth, int groups, ConvolutionNormalization normalization, bool useBias) Creates the layer.

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].
IReadOnlyList<ValueTuple<string, Tensor<T>>> GetRegisteredBuffers()
void ResetState()
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) Replaces trainable parameter tensors (e.g., with ParameterBuffer views).
void ZeroGrad() Clears all gradient fields discovered by convention ({paramName}Gradient).