@ptrblck Thank you!!! Makes sense.
Just a follow up question.
Lets say your network is like this:
class MyModel(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
and you define the weight like this:
def weights_init(m):
if isinstance(m, nn.Conv2d):
nn.init.xavier_uniform(m.weight.data)
nn.init.xavier_uniform(m.bias.data)
Am i putting it in a right place in th following?
class MyModel(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def weights_init(m):
if isinstance(m, nn.Conv2d):
nn.init.xavier_uniform(m.weight.data)
nn.init.xavier_uniform(m.bias.data)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x
Or you suggest to put it in another way?
I know it is kinda a stupid question, but the reason that im asking it is that I was wondering if if there is a way to put it inside the init(self), but im not sure if it is possible and also not sure if it is even a good idea.
So just was wondering.
Thanks