GraphSpec Classifier Head #
A classifier takes a typed feature chain, flattens its output, and applies a linear head. The feature chain determines its own depth, channel widths, spatial geometry, and parameter shapes. Its stages can use different convolution and pooling configurations.
def
NN.GraphSpec.Models.classifier
{parameters : List Spec.Shape}
{input featureShape : Spec.Shape}
(features : Chain parameters input featureShape)
(outputSize : ℕ)
:
Attach a linear classifier to an arbitrary feature chain.
Parameters remain in feature-chain order, followed by the head's weight and bias. An identity feature chain gives a linear classifier on the flattened input. The general chain-to-DAG conversion applies to the resulting classifier without a model-specific wrapper.
Instances For
theorem
NN.GraphSpec.Models.classifier_interp
{α : Type}
[TorchLean.Storage α]
[Context α]
{parameters : List Spec.Shape}
{input featureShape : Spec.Shape}
{outputSize : ℕ}
(features : Chain parameters input featureShape)
(state : TorchLean.TensorPack α parameters)
(head : Spec.LinearSpec α featureShape.size outputSize)
(x : TorchLean.Tensor α input)
:
Interp.spec (classifier features outputSize)
(state.append
(TorchLean.TensorPack.cons head.weights (TorchLean.TensorPack.cons head.bias TorchLean.TensorPack.nil)))
x = Spec.linearSpec head (Interp.spec features state x).flattenSpec
The classifier applies its head to the flattened feature output, preserving parameter order.