Tutorial 81: SNN Transfer Learning¶
Pretrain, save, load, freeze, fine-tune. The standard ML workflow adapted for spiking neural networks.
Save and Load Checkpoints¶
from sc_neurocore.transfer import (
save_checkpoint, load_checkpoint, SNNCheckpoint, TransferConfig,
)
# Save trained model
ckpt = SNNCheckpoint(
weights=model_weights,
layer_names=["h1", "out"],
layer_sizes=[(784, 256), (256, 10)],
)
save_checkpoint(ckpt, "mnist_snn")
# Load checkpoint
ckpt = load_checkpoint("mnist_snn")
Freeze and Fine-Tune¶
from sc_neurocore.transfer.fine_tune import apply_transfer_config
# Freeze all layers except the last (readout)
config = TransferConfig(freeze_until=0, lr_head=0.001)
ckpt, per_layer_lr = apply_transfer_config(ckpt, config)
# per_layer_lr: [0.0, 0.001] — first layer frozen, second trains
Transfer Learning Workflow¶
- Pretrain on large dataset (e.g., MNIST 60K examples)
- Save checkpoint with
save_checkpoint() - Load on new task with
load_checkpoint() - Freeze feature extraction layers
- Fine-tune readout layer on new task (few examples suffice)
SNN transfer learning preserves learned temporal dynamics — spike timing patterns transfer across tasks, not just weight magnitudes.
API Reference¶
sc_neurocore.transfer
¶
Save, load, freeze, fine-tune SNN models. The foundation of modern ML.
SNNCheckpoint
dataclass
¶
Complete SNN model checkpoint.
Source code in src/sc_neurocore/transfer/checkpoint.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
TransferConfig
dataclass
¶
Configuration for transfer learning.
Parameters¶
freeze_until : str or int Freeze all layers up to (and including) this layer name or index. lr_backbone : float Learning rate for frozen layers (usually 0 or very small). lr_head : float Learning rate for unfrozen layers.
Source code in src/sc_neurocore/transfer/fine_tune.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
save_checkpoint(checkpoint, path)
¶
Save SNN checkpoint to .npz + .json.
Parameters¶
checkpoint : SNNCheckpoint path : str or Path Base path (without extension). Creates path.npz and path.json.
Source code in src/sc_neurocore/transfer/checkpoint.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
load_checkpoint(path)
¶
Load SNN checkpoint from .npz + .json.
Parameters¶
path : str or Path Base path (without extension).
Returns¶
SNNCheckpoint
Source code in src/sc_neurocore/transfer/checkpoint.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
freeze_layers(checkpoint, layer_names=None, until_index=None)
¶
Freeze layers (mark as non-trainable).
Parameters¶
checkpoint : SNNCheckpoint layer_names : list of str, optional Specific layers to freeze. until_index : int, optional Freeze all layers with index <= until_index.
Returns¶
SNNCheckpoint with frozen_layers updated
Source code in src/sc_neurocore/transfer/fine_tune.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
unfreeze_layers(checkpoint, layer_names=None, all_layers=False)
¶
Unfreeze layers (mark as trainable).
Parameters¶
checkpoint : SNNCheckpoint layer_names : list of str, optional Specific layers to unfreeze. all_layers : bool If True, unfreeze everything.
Source code in src/sc_neurocore/transfer/fine_tune.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |