Hi! I’m very new with trying to learn pytorch. When trying to compare models i found that the outputs are different.
Simple CNN:
class NetOne(nn.Module):
def init(self):
super(NetOne, self).init()
self.c1 = 16
self.c2 = 8
self.c3 = 4
self.size = 32
self.fclen1=419
self.fclen2=10
self.conv1 = nn.Conv2d(3, self.c1, 3, padding=1)
self.conv2 = nn.Conv2d(self.c1, self.c2, 3, padding=1)
self.conv3 = nn.Conv2d(self.c2, self.c3, 3, padding=1)
self.bn1 = nn.BatchNorm2d(self.c1)
self.bn2 = nn.BatchNorm2d(self.c2)
self.bn3 = nn.BatchNorm2d(self.c3)
self.fc1 = nn.Linear(self.c3 * self.size * self.size, self.fclen2)
self.fc2 = nn.Linear(self.fclen1, self.fclen2)
self.dropout = nn.Dropout(0.25)
def forward(self, x):
    x = F.relu(self.bn1(self.conv1(x)))
    x = self.dropout(x)
    x = F.relu(self.bn2(self.conv2(x)))
    x = F.relu(self.bn3(self.conv3(x)))
    x = x.view(-1, self.c3 * self.size * self.size)
    x = self.fc1(x)
    return x

And using it:
   model1 = NetOne()
   model2 = NetOne()

…
for _, (data, target) in enumerate(train_loader):
if train_on_gpu:
data1, target1 = data.cuda(), target.cuda()
data2, target2 = data.cuda(), target.cuda()
else :
data1, target1 = data, target
data2, target2 = data, target
optimizer1.zero_grad()
optimizer2.zero_grad()
output1 = model1(data1)
output2 = model2(data2)
for i in range (len(s1)):
if s1[i] != s2[i]:
print(‘loss error %d : %f %f’ % (iterNum, s1[i], s2[i]))
gives a lot of lines like:
loss error 0 : -0.132742 0.350880
loss error 1 : -26.758894 -30.239246
loss error 2 : -10.001531 -12.009613
Can you suggest what’s wrong, please.