CNN PyTorch Reference Import #
CNN reference weight import from a PyTorch-style state_dict.
We mirror the common PyTorch naming convention for modules:
conv1.weight,conv1.biasconv2.weight,conv2.biasfc.weight,fc.bias
Each tensor is expected to be encoded as nested JSON arrays whose shape matches the expected
TorchLean Shape.
structure
Import.PyTorch.CNN.Parameters
(inputChannels outputChannels kernelHeight kernelWidth flattenedWidth : ℕ)
:
Parameters for the example two-block CNN imported from a PyTorch state_dict.
This matches the keys used by the exporter (conv1.*, conv2.*, fc.*) and pins down the exact
shapes expected by TorchLean.
- firstConvolutionWeight : TorchLean.Tensor Float [outputChannels, inputChannels, kernelHeight, kernelWidth]
First convolution kernel, in PyTorch
(output, input, height, width)layout. - firstConvolutionBias : TorchLean.Tensor Float [outputChannels]
First convolution bias.
- secondConvolutionWeight : TorchLean.Tensor Float [outputChannels, outputChannels, kernelHeight, kernelWidth]
Second convolution kernel.
- secondConvolutionBias : TorchLean.Tensor Float [outputChannels]
Second convolution bias.
- classifierWeight : TorchLean.Tensor Float [outputChannels, flattenedWidth]
Classifier weight, in PyTorch
(output, input)layout. - classifierBias : TorchLean.Tensor Float [outputChannels]
Classifier bias.
Instances For
def
Import.PyTorch.CNN.load
(inputChannels outputChannels kernelHeight kernelWidth flattenedWidth : ℕ)
(json : Lean.Json)
:
Option (Parameters inputChannels outputChannels kernelHeight kernelWidth flattenedWidth)
Load CNN parameters from JSON using PyTorch state_dict keys.