Pytorch 快速参数权重初始化

定义一个函数:

这里比如要初始化2维卷积权重值,采用xaiver 数据分布,还有很多其他的数据分布可以探索

def weights_init(m):
    if isinstance(m, nn.Conv2d):
        xavier(m.weight.data)
        xavier(m.bias.data)

然后定义一个含2维卷积的网络,并对该网络中的2维卷积层权重进行初始化操作。

net = Residual() # generate an instance network from the Net class
net.apply(weights_init) # apply weight init

Pytorch 快速参数权重初始化_第1张图片

你可能感兴趣的:(pytorch,人工智能,python)