I am new to pytorch, and I am confused when I go through the vision models of Alexnet and VGG, for Alexnet, there is no weight initialization function, and other models have., such as for VGG, there is a function def _initialize_weights(self). So my question is, why?
Hmm, maybe because it’s too old? But you can generate them by yourself by apply the init rule.
def init_weights(m): if isinstance(m, nn.Linear): torch.nn.init.xavier_uniform(m.weight) m.bias.data.fill_(0.) elif isinstance(m, nn.Conv2d): torch.nn.init.xavier_uniform(m.weight) model = torchvisions.models.alexnet() model.apply(init_weights)