keras BatchNormalization axis clarification

前端 未结 3 722
遥遥无期
遥遥无期 2020-12-24 07:11

The keras BatchNormalization layer uses axis=-1 as a default value and states that the feature axis is typically normalized. Why is this the case?

I sup

3条回答
  •  北海茫月
    2020-12-24 08:03

    The confusion is due to the meaning of axis in np.mean versus in BatchNormalization.

    When we take the mean along an axis, we collapse that dimension and preserve all other dimensions. In your example data.mean(axis=0) collapses the 0-axis, which is the vertical dimension of data.

    When we compute a BatchNormalization along an axis, we preserve the dimensions of the array, and we normalize with respect to the mean and standard deviation over every other axis. So in your 2D example BatchNormalization with axis=1 is subtracting the mean for axis=0, just as you expect. This is why bn.moving_mean has shape (4,).

提交回复
热议问题