TorchLean API

NN.API.Models.Cnn

Convolutional Classifier #

The classifier accepts any batchShape and number of spatial axes. Each stage independently configures its convolution, activation, optional dropout, and pooling. The linear head consumes the final feature map; an empty stage list applies the head directly to the flattened input.

Configuration for a convolutional classifier over d spatial axes.

  • inputChannels : ℕ

    Number of channels in each input sample.

  • spatial : Tensor ℕ [d]

    Extent of each spatial axis.

  • Ordered convolution/activation/pooling stages.

  • classCount : ℕ

    Number of classifier logits per sample.

Instances For

    Validate the complete classifier geometry before allocating convolution or head parameters.

    Instances For
      @[reducible, inline]
      abbrev TorchLean.nn.models.CNN.Config.inputShape {d : ℕ} (config : Config d) (batchShape : Shape := []) :

      Input tensor shape after prepending an arbitrary batch shape.

      Instances For
        @[reducible, inline]
        abbrev TorchLean.nn.models.CNN.Config.outputShape {d : ℕ} (config : Config d) (batchShape : Shape := []) :

        Classifier output shape with the same batch shape as the input.

        Instances For
          def TorchLean.nn.models.cnn {d : ℕ} (config : CNN.Config d) (batchShape : Shape := []) :
          Builder (Sequential (config.inputShape batchShape) (config.outputShape batchShape))

          Build the configured feature stages, flatten their output, and apply the linear head.

          Instances For
            def TorchLean.nn.models.cnn.buildStages {d : ℕ} (config : CNN.Config d) (batchShape : Shape) (channels : ℕ) (spatial : Tensor ℕ [d]) (stages : List (ConvPoolBlock.Config d)) :
            Builder (Sequential (batchShape.concat ((spatial.to Shape).prependDim channels)) (config.outputShape batchShape))
            Instances For