Hello Konstantinos!



 kkonstantinidis:

class LeNet(nn.Module):
    def __init__(self):
        super(LeNet, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5, 1)
        self.conv2 = nn.Conv2d(20, 50, 5, 1)
        self.fc1 = nn.Linear(4*4*50, 500)
...

network=LeNet()
...
logits = network(X_batch)

My problem is that if I run this code twice I will get different values for logits


When you construct your LeNet (two separate times), you
construct its layers, e.g.,
self.fc1 = nn.Linear(4*4*50, 500), (two separate times).
By default, pytorch randomly initializes the layer weights, so you
get two differing sets of weights, and hence differing output
values for logits.
You can check this by printing out some example weights from
network each individual time you initialize it.
Best.
K. Frank