Residual Convolutional Classifier #
The model is polymorphic in spatial rank. Residual branches operate on a common typed shape, and global average pooling reduces every spatial axis before the classifier head.
Configuration for a residual classifier over d spatial axes.
- batch : ℕ
Number of independent samples processed together.
- inChannels : ℕ
Number of channels in each input sample.
Extent of each spatial axis.
Spatial axes are nonempty, as required by global average pooling.
- numClasses : ℕ
Number of classifier logits per sample.
Instances For
Input tensor shape (batch, inChannels, spatial...).
Instances For
Activation shape shared by the residual branches.
Instances For
Classifier output shape (batch, numClasses).
Instances For
def
TorchLean.nn.models.Internal.sameSpatialConv
{d batch : ℕ}
(spatial : Vector ℕ d)
(spatialNonzero : ∀ (i : Fin d), spatial.get i ≠ 0)
(inChannels outChannels : ℕ)
[NeZero inChannels]
:
M
(Sequential (Spec.Shape.dim batch (Spec.Shape.ofList (inChannels :: spatial.toList)))
(Spec.Shape.dim batch (Spec.Shape.ofList (outChannels :: spatial.toList))))
Shape-preserving convolution used by the residual trunk.
Instances For
def
TorchLean.nn.models.resnet
{d : ℕ}
(cfg : ResNetConfig d)
(hInChannels : cfg.inChannels ≠ 0 := by decide)
(hHiddenChannels : cfg.hiddenChannels ≠ 0 := by decide)
:
M (Sequential (resnetInShape cfg) (resnetOutShape cfg))
Build a convolutional stem, two residual blocks, global pooling, and a linear classifier.