Custom weight initialization in PyTorch
问题 What would be the right way to implement a custom weight initialization method in PyTorch ? I believe I can't directly add any method to 'torch.nn.init` but wish to initialize my model's weights with my own proprietary method. 回答1: You can define a method to initialize the weights according to each layer: def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv2d') != -1: m.weight.data.normal_(0.0, 0.02) elif classname.find('BatchNorm') != -1: m.weight.data.normal_(1.0, 0