bn_momentum
Stepwise exponential decay of the BatchNorm momentum over the epochs.
Classes:
-
BNMomentumSchedulerβApply
bn_momentumto a model at the start of each epoch.
BNMomentumScheduler [source] ΒΆ
BNMomentumScheduler(
model: Module,
*,
init: float = 0.5,
decay_rate: float = 0.5,
decay_step: int = 20,
clip: float = 0.001,
)
Apply bn_momentum to a model at the start of each epoch.
Parameters:
-
model(Module) βModel whose
BatchNormlayers are scheduled. -
init(float, default:0.5) βInitial momentum \(m_0\).
-
decay_rate(float, default:0.5) βPer-step multiplicative decay \(\gamma\).
-
decay_step(int, default:20) βEpochs between decay steps \(s\).
-
clip(float, default:0.001) βLower bound \(m_\text{clip}\).
Example
Methods:
-
stepβSet the momentum of
epochon the model'sBatchNormlayers and return it.
bn_momentum [source] ΒΆ
bn_momentum(
epoch: int,
*,
init: float = 0.5,
decay_rate: float = 0.5,
decay_step: int = 20,
clip: float = 0.001,
) -> float
The decayed BatchNorm momentum of an epoch.
\[ m_\text{epoch} = \max\left(m_0 \cdot \gamma^{\lfloor \text{epoch} / s \rfloor},\; m_\text{clip}\right) \]
Parameters:
-
epoch(int) βZero-based epoch.
-
init(float, default:0.5) βInitial momentum \(m_0\).
-
decay_rate(float, default:0.5) βPer-step multiplicative decay \(\gamma\).
-
decay_step(int, default:20) βEpochs between decay steps \(s\).
-
clip(float, default:0.001) βLower bound \(m_\text{clip}\).
Returns:
-
floatβThe momentum to set on the
BatchNormlayers for that epoch.