pytorch网络参数初始化

在定义网络时,pythorch会自己初始化参数,但也可以自己初始化,详见官方实现

for m in self.modules():
        if isinstance(m, nn.Conv2d):
            nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
        elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
            nn.init.constant_(m.weight, 1)
            nn.init.constant_(m.bias, 0)
posted @ 2020-04-10 13:29  happy_fan  阅读(2857)  评论(0编辑  收藏  举报