Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Weight Files

Supported Formats

FormatDescription
Directory of .npy filesEach file named {layer_id}.{param}.npy (e.g., fc1.weight.npy, fc1.bias.npy)
.npz archiveKeys must match {layer_id}.{param} (e.g., fc1.weight, fc1.bias)

Naming Convention

The weights config key points to the weight source. nnc resolves it relative to the .nnl file’s directory.

[config]
weights = "weights/"       # directory of .npy files
# or
weights = "model.npz"      # single .npz archive

Expected Shapes Per Layer

LayerParameterShape
Denseweight[input_dim, units]
Densebias[units]
Conv2Dweight[filters, in_channels, kH, kW]
Conv2Dbias[filters]
BatchNormgamma[channels]
BatchNormbeta[channels]
BatchNormrunning_mean[channels]
BatchNormrunning_var[channels]

Data Types

PrecisionWeight dtype
"float32"float32
"float64"float64

Generating Test Weights (Python)

import numpy as np

# Create weights matching a Dense layer with 784 inputs and 128 units
np.save("fc1.weight.npy", np.random.randn(784, 128).astype(np.float32))
np.save("fc1.bias.npy", np.zeros(128, dtype=np.float32))

# Or bundle into an .npz archive
np.savez("model.npz",
    **{"fc1.weight": np.random.randn(784, 128).astype(np.float32),
       "fc1.bias": np.zeros(128, dtype=np.float32)})

Error Messages

ErrorMeaningFix
E003: missing weightA layer expects a weight file or key that was not found in the weight source.Ensure the weight source contains an entry named {layer_id}.{param} for every parameterised layer.
Shape mismatchThe shape of a loaded weight does not match what the layer definition expects (e.g., expected [784, 128] but found [128, 784]).Regenerate or transpose the weight so its shape matches the table above.