in tensorflow, default initialization used is glorot normal initialization which is also known as xavier normal initialization. To use the same setting in pytorch, the following practice should be done.

2d convolution module example

self.conv1 = torch.nn.Conv2d(3, 16, 3, padding=1)

torch.nn.init.xavier_normal_(self.conv1.weight)
torch.nn.init.zeros_(self.conv1.bias)

linear module example

self.linear2 = torch.nn.Linear(32,1)
torch.nn.init.xavier_normal_(self.linear2.weight)
torch.nn.init.zeros_(self.linear2.bias)

pytorch supports other initialization functions, and one can use those initialization functions in other situations as they see fit in a similar fashion as above.


0 Comments

Leave a Reply

Your email address will not be published.