211014记录:pytorch模型中初始化公式(共13种)总结torch.nn.init

本文汇总了PyTorch中13种模型初始化方法,包括uniform_、normal_、constant_等,并提供了官方网址和相关链接,详细解释了如Xavier、Kaiming等初始化策略。
摘要由CSDN通过智能技术生成

torch官方网址:
https://pytorch.org/docs/stable/nn.init.html

1、torch.nn.init.uniform_(tensor, a=0.0, b=1.0)#均匀分布U(a,b)
2、 torch.nn.init.normal_(tensor, mean=0.0, std=1.0)
3、torch.nn.init.constant_(tensor, val)
4、 torch.nn.init.ones_(tensor)
5、 torch.nn.init.zeros_(tensor)
6、torch.nn.init.eye_(tensor)
7、 torch.nn.init.dirac_(tensor, groups=1)

import torch
from torch import nn 
w = torch.empty(3, 5)
w
tensor([[0.8851, 0.1706, 1.0505, 1.1845, 0.8852],
        [0.2051, 0.8593, 0.3408, 0.0350, 0.4771],
        [0.0308, 0.6101, 0.9387, 1.2147, 0.2101]])
nn.init.constant_(w, 0.3)
tensor([[0.3000, 0.3000, 0.3000, 0.3000, 0.3000],
        [0.3000, 0.3000, 0.3000, 0.3000, 0.3000],
        [0.3000, 0.3000, 0.3000, 0.3000, 0.3000]])
 nn.init.ones_(w)
tensor([[1., 1., 1., 1., 1.],
        [1., 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值