区别于默认初始化,自定义初始化
# 内置初始化
def init_normal(m): # m is net
if type(m) == nn.Linear():
# "_" is replace, is not return
nn.init.normal_(m.weight, mean=0. std=0.01) # 正态分布
# nn.init.constant_(m.weight, 1)
nn.init.zeros_(m.bias) # 置零
net.apply(init_normal) # 对网络进行遍历,遍历执行init_normal
net[0].weight.data[0]
net[0].bias.data[0]