How I can set an initialization for Conv kernels similarly to Keras

How I could initialize the kernels of a convolution layer in pytorch? e.g. He initialization

In Keras It’s as simple as

y = Conv1D(..., kernel_initializer='he_uniform')(x)

But looking the signature of Conv1d in pytorch I don’t see such a parameter

torch.nn.Conv1d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)

What is the appropriate way to get similar behavior in pytorch?

Here is a small example how to use the same initialization as is used in Keras.

1 Like