While alive, merges bn's affine map into conv's weights and makes bn an exact identity; on destruction, restores both bit for bit.
More...
#include <batch_norm_fold.hpp>
While alive, merges bn's affine map into conv's weights and makes bn an exact identity; on destruction, restores both bit for bit.
- Note
- With s_c = gamma_c / sqrt(running_var_c + eps), the merged convolution has kernel w'[c] = s_c * w[c] and bias b'[c] = s_c * (b[c] - running_mean_c) + beta_c. The pair computes the same function before and during the fold (up to float rounding), but LRP now distributes relevance through one affine layer with the convolution's own rule, instead of passing it unchanged through BatchNorm's identity rule.
-
Use it as a scope around explaining:
{ BatchNormFold fold(conv, bn); auto r = lrp.explain(...); }. Don't train while a fold is active: gradients would update the merged weights, and the restore would overwrite those updates.
◆ BatchNormFold() [1/3]
- Exceptions
-
| std::invalid_argument | if bn is in training mode (its statistics are not fixed, so there is no single affine map to fold), or if bn's channel count differs from conv's output channels. |
| std::logic_error | if bn is already folded. |
◆ ~BatchNormFold()
| pulsatrix::BatchNormFold::~BatchNormFold |
( |
| ) |
|
◆ BatchNormFold() [2/3]
| pulsatrix::BatchNormFold::BatchNormFold |
( |
const BatchNormFold & |
| ) |
|
|
delete |
◆ BatchNormFold() [3/3]
◆ operator=() [1/2]
◆ operator=() [2/2]
The documentation for this class was generated from the following file: