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.,