Created
November 27, 2017 23:06
-
-
Save zackenton/989792b3becd258fc19a396f0fb28596 to your computer and use it in GitHub Desktop.
initilization minimal example, here for conv2d init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model(nn.Module): | |
''' | |
Some Model, in this case a convolution single layer | |
''' | |
def __init__(self, in_channels, out_channels, kernel_size): | |
super(Model, self).__init__() | |
self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size) | |
# Initialize weights | |
for m in self.modules(): | |
# set only initialization on these types of layers | |
if isinstance(m, nn.Conv2d): | |
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels | |
m.weight.data.normal_(0, math.sqrt(2. / n)) | |
m.bias.data.zero_() | |
def forward(self, x): | |
x = self.conv2d(x) | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment