mmcls.core.PreciseBNHook¶
- class mmcls.core.PreciseBNHook(num_samples: int = 8192, interval: int = 1)[source]¶
Precise BN hook.
Recompute and update the batch norm stats to make them more precise. During training both BN stats and the weight are changing after every iteration, so the running average can not precisely reflect the actual stats of the current model.
With this hook, the BN stats are recomputed with fixed weights, to make the running average more precise. Specifically, it computes the true average of per-batch mean/variance instead of the running average. See Sec. 3 of the paper Rethinking Batch in BatchNorm <https://arxiv.org/abs/2105.07576> for details.
This hook will update BN stats, so it should be executed before
CheckpointHookandEMAHook, generally set its priority to “ABOVE_NORMAL”.