snn.utils

Data

snn.utils.to_categorical(y, num_classes=None)[source]

Convert integer class labels to one-hot vectors.

snn.utils.normalize(x, axis=None)[source]

Min-max normalize to [0, 1].

snn.utils.standardize(x, axis=None)[source]

Standardize to zero mean and unit variance.

snn.utils.train_test_split(x, y, test_size=0.2, shuffle=True, seed=None)[source]

Split arrays into train and test sets.

snn.utils.batch_generator(x, y, batch_size=32, shuffle=True)[source]

Yield (x_batch, y_batch) mini-batches.

Gradient Utilities

snn.utils.clip_gradients(grads, max_norm=5.0)[source]

Global gradient norm clipping.

Learning Rate Schedules

snn.utils.learning_rate_schedule(initial_lr, decay_rate=0.96, decay_steps=1000)[source]

Return a callable exponential LR schedule.

snn.utils.cosine_annealing(initial_lr, t_max, eta_min=0.0)[source]

Return a callable cosine annealing LR schedule.

snn.utils.warmup_schedule(initial_lr, warmup_steps, base_schedule=None)[source]

Linear warmup followed by an optional base schedule.

Callbacks

class snn.utils.EarlyStopping(monitor='val_loss', patience=5, min_delta=0.0, mode='auto', restore_best_weights=False, verbose=1)[source]

Bases: object

Stop training when a monitored metric has stopped improving.

Parameters:
  • monitor (str) – Name of the metric to watch (e.g. ‘val_loss’).

  • patience (int) – Number of epochs with no improvement before stopping.

  • min_delta (float) – Minimum change to qualify as an improvement.

  • mode (str) – ‘min’ for loss-like metrics, ‘max’ for accuracy-like.

  • restore_best_weights (bool) – If True, restore the best weights when training stops.

property stopped
class snn.utils.ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=3, min_lr=1e-06, verbose=1)[source]

Bases: object

Reduce learning rate when a metric has stopped improving.

Parameters:
  • monitor (str)

  • factor (float) – Factor by which the learning rate will be reduced.

  • patience (int)

  • min_lr (float) – Lower bound for the learning rate.

  • verbose (int)