TorchLean API

NN.API.Models.ResNet

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.

  • spatial : Vector d

    Extent of each spatial axis.

  • spatialNonzero (i : Fin d) : self.spatial.get i 0

    Spatial axes are nonempty, as required by global average pooling.

  • hiddenChannels :

    Channel width used by the residual trunk.

  • 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) :

            Build a convolutional stem, two residual blocks, global pooling, and a linear classifier.

            Instances For