TorchLean API

NN.Spec.Models.Cnn

Convolutional Network Specifications #

This module defines a two-block convolutional network over an arbitrary number of spatial axes. Its spatial parameters are vectors, so the same model definition applies to sequence, image, volume, and higher-rank data. The forward and reverse-mode specifications use the generic convolution and pooling operations.

This is a standalone reference model. The executable nn.models.cnn accepts independently configured stages, and NN/Runtime/PyTorch/Export/CNN.lean renders its own configuration. Neither is constructed from this specification, and no equivalence theorem connects them here.

def Models.Cnn.blockOutSpatial {d : ℕ} (spatial kernel convStride convPadding poolKernel poolStride poolPadding : TorchLean.Tensor ℕ [d]) :

Spatial shape after one convolution followed by one pooling operation.

Instances For
    def Models.Cnn.outputSpatial {d : ℕ} (spatial kernel convStride₁ convPadding₁ convStride₂ convPadding₂ poolKernel poolStride₁ poolPadding₁ poolStride₂ poolPadding₂ : TorchLean.Tensor ℕ [d]) :

    Spatial shape after two convolution-pooling blocks.

    Instances For
      def Models.Cnn.featureShape {d : ℕ} (channels : ℕ) (spatial kernel convStride₁ convPadding₁ convStride₂ convPadding₂ poolKernel poolStride₁ poolPadding₁ poolStride₂ poolPadding₂ : TorchLean.Tensor ℕ [d]) :

      Feature-map shape after the second pooling operation.

      Instances For
        def Models.Cnn.featureSize {d : ℕ} (channels : ℕ) (spatial kernel convStride₁ convPadding₁ convStride₂ convPadding₂ poolKernel poolStride₁ poolPadding₁ poolStride₂ poolPadding₂ : TorchLean.Tensor ℕ [d]) :

        Number of scalar features presented to the linear head.

        Instances For

          Hyperparameters for a two-block convolutional network of spatial rank d.

          Instances For
            structure Models.TwoBlockCnn.Config.WF {d : ℕ} (config : Config d) :

            Conditions needed by convolutional and pooling implementations.

            Instances For

              The default configuration at any spatial rank.

              Instances For

                The default configuration is well formed.

                structure Models.TwoBlockCnn.Model {d : ℕ} (config : Config d) (inChannels : ℕ) (spatial : TorchLean.Tensor ℕ [d]) (α : Type) [TorchLean.Storage α] (hCfg : config.WF) :

                A generic two-block convolutional network with an explicit linear head.

                Instances For
                  structure Models.TwoBlockCnn.Grads {d : ℕ} (config : Config d) (inChannels : ℕ) (spatial : TorchLean.Tensor ℕ [d]) (α : Type) [TorchLean.Storage α] :

                  Parameter gradients for Model.

                  Instances For
                    def Models.TwoBlockCnn.Model.forward {α : Type} [TorchLean.Storage α] [Context α] {d : ℕ} {config : Config d} {inChannels : ℕ} {spatial : TorchLean.Tensor ℕ [d]} {hCfg : config.WF} (m : Model config inChannels spatial α hCfg) (x : TorchLean.Tensor α (Spec.Shape.ofList (inChannels :: spatial.to (List ℕ)))) :

                    Forward pass for Model.

                    Instances For
                      def Models.TwoBlockCnn.Model.backward {α : Type} [TorchLean.Storage α] [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] {d : ℕ} {config : Config d} {inChannels : ℕ} {spatial : TorchLean.Tensor ℕ [d]} {hCfg : config.WF} (m : Model config inChannels spatial α hCfg) (x : TorchLean.Tensor α (Spec.Shape.ofList (inChannels :: spatial.to (List ℕ)))) (gradOutput : TorchLean.Tensor α [config.outputSize]) :
                      Grads config inChannels spatial α × TorchLean.Tensor α (Spec.Shape.ofList (inChannels :: spatial.to (List ℕ)))

                      Reverse-mode parameter and input derivatives for Model.

                      Instances For