ShapeRelationKind

Enums · AiDotNet.NeuralNetworks.Layers

How a layer’s output shape is determined by its input shape, declared per LAYER TYPE rather than per model instance.

For Beginners

Instead of a layer writing down “my output is 8x32x32”, it writes down the RULE it follows — “my output is the same size as my input”, or “my output shrinks by the stride”. A rule can be checked against reality; a number can only be compared to one.

How It Works

A declared output shape on its own cannot say whether it is wrong or merely describing a different input than the one that arrived. A relation can: if a layer states that it preserves shape, then a declared output of [8, 32, 32] is a claim that its input was [8, 32, 32], and an actual input of [8, 8, 8] proves the DECLARATION’s provenance wrong rather than the layer. That distinction is the whole point: it moves the finger from the layer, which computed correctly, to whatever wrote the declaration.

Relations are per layer type and there are only a few shapes of them — most layers preserve their input, and the rest follow a one-line formula — so unlike per-model declared numbers they do not have to be re-established every time a new model is added.

Beyond PyTorch: nn.Module declares no shape and states no rule, so a mis-wired stride chain surfaces only as a runtime error inside some later kernel, with nothing to identify which layer’s assumption was violated. torch.fx ShapeProp and the meta device can tell you what a graph DID produce, but neither lets a module state what it is supposed to produce and be held to it.

Fields

Field Summary
ShapeRelationKind ChannelOnly Leading (channel) axis is set by the layer; the remaining spatial axes are preserved.
ShapeRelationKind Convolutional Leading axis is set by the layer; spatial axes follow the convolution formula floor((in + 2*padding - kernel) / stride) + 1.
ShapeRelationKind FeatureOnly TRAILING (feature) axis is set by the layer; every leading axis is preserved — the feature-last counterpart of ChannelOnly.
ShapeRelationKind Identity Output shape equals input shape, axis for axis — normalization, activation, dropout.
ShapeRelationKind Unknown The layer states nothing about how output relates to input; no check is performed.
int value__