density_layers.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:VAESSL 作者: lovecambi 项目源码 文件源码
def __init__(self, incoming, axes='auto', epsilon=1e-6, alpha=1e-2,
                 beta=init.Constant(0), gamma=init.Constant(1),
                 mean=init.Constant(0), std=init.Constant(1), **kwargs):
        super(MyBatchNormLayer, self).__init__(incoming, **kwargs)

        if axes == 'auto':
            # default: normalize over all but the second axis
            axes = (0,) + tuple(range(2, len(self.input_shape)))
        elif isinstance(axes, int):
            axes = (axes,)
        self.axes = axes

        self.epsilon = epsilon
        self.alpha = alpha

        # create parameters, ignoring all dimensions in axes
        shape = [size for axis, size in enumerate(self.input_shape)
                 if axis not in self.axes]
        if any(size is None for size in shape):
            raise ValueError("BatchNormLayer needs specified input sizes for "
                             "all axes not normalized over.")
        if beta is None:
            self.beta = None
        else:
            self.beta = self.add_param(beta, shape, 'beta',
                                       trainable=True, regularizable=False)
        if gamma is None:
            self.gamma = None
        else:
            self.gamma = self.add_param(gamma, shape, 'gamma',
                                        trainable=True, regularizable=True)
        self.mean = self.add_param(mean, shape, 'mean',
                                   trainable=False, regularizable=False)
        self.std = self.add_param(std, shape, 'std',
                                      trainable=False, regularizable=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号