How It WorksΒΆ
π§ ContextualConv LayersΒΆ
ContextualConv1d and ContextualConv2d extend standard convolutions by allowing the output to be modulated by a global context vector.
π Forward PassΒΆ
Input tensor
xis passed through a standardnn.Conv1dornn.Conv2dlayer.If a context vector
cis provided:It is passed through a shared
ContextProcessormodule:If
h_dimis not set: just aLinear(context_dim β out_channels)If
h_dimis set: an MLPLinear β ReLU β Linear
The result is a bias of shape
(B, out_channels)This bias is broadcast over the output and added as a per-channel bias
π§© Architecture (1D/2D)ΒΆ
x β Conv1d/2d β y
c β ContextProcessor β bias
y + bias β final output
β NotesΒΆ
The context vector is global β it does not vary across spatial/temporal locations.
The
ContextProcessoris shared across all locations and all groups (if used).If
context_dimis not set, the layer behaves like a standard convolution.