How are layer weights and biases initialized by default?

Yes, it looks good.
Some small side notes: .data shouldn’t be used anymore, so just use the inplace init methods directly passing the parameters:

def weights_init(m):
    if isinstance(m, nn.Conv2d):
        torch.nn.init.xavier_uniform_(m.weight)
        torch.nn.init.zeros_(m.bias)

model.apply(weights_init)
8 Likes