init.py 文件源码

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

项目:braindecode 作者: robintibor 项目源码 文件源码
def glorot_weight_zero_bias(model):
    """
    Initalize parameters of all modules
    by initializing weights with glorot  uniform/xavier initialization,
    and setting biases to zero.
    Weights from batch norm layers are set to 1.

    Parameters
    ----------
    model: Module
    """
    for module in model.modules():
        if hasattr(module, 'weight'):
            if not ('BatchNorm' in module.__class__.__name__):
                init.xavier_uniform(module.weight, gain=1)
            else:
                init.constant(module.weight, 1)
        if hasattr(module, 'bias'):
            if module.bias is not None:
                init.constant(module.bias, 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号