I built a small auto-encoder for greyscale images. It is there to make some tests, so I train it often, and I have a strange behavior.
On some initialisations, it does not converge. I mean, the MSE loss stay around 0.25 and never get down. The reconstructed images are uniform grey.
On most other initialisations, it converges to a loss around 0.13 during the first epoch.The reconstructed images are very blurry but it is a excepted for such a small network.
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
Conv2d-1 [-1, 16, 288, 288] 160
MaxPool2d-2 [-1, 16, 72, 72] 0
Conv2d-3 [-1, 8, 72, 72] 1,160
MaxPool2d-4 [-1, 8, 18, 18] 0
Conv2d-5 [-1, 3, 18, 18] 219
MaxPool2d-6 [-1, 3, 9, 9] 0
Conv2d-7 [-1, 3, 9, 9] 84
Upsample-8 [-1, 3, 18, 18] 0
Conv2d-9 [-1, 8, 18, 18] 224
Upsample-10 [-1, 8, 72, 72] 0
Conv2d-11 [-1, 16, 72, 72] 1,168
Upsample-12 [-1, 16, 288, 288] 0
Conv2d-13 [-1, 1, 288, 288] 145
================================================================
Total params: 3,160
Trainable params: 3,160
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.32
Forward/backward pass size (MB): 22.84
Params size (MB): 0.01
Estimated Total Size (MB): 23.17
----------------------------------------------------------------
None
It is PyTorch 1.10.2 with Cuda 10.2.
The parameters are:
BATCH_SIZE = 8
EPOCHS = 10
normalize = transforms.Normalize(((0.5),(0.5)))
criterion = nn.MSELoss()
optimizer = optim.Adadelta(self.net.parameters())
The train loop is quite simple:
for epoch in range(self.epochs):
# Iterate over the data in batches
for i, batch_data in enumerate(self.train_data.loader, 0):
# get the inputs
inputs = batch_data[0].to(self.device)
# zero the parameter gradients
optimizer.zero_grad()
# forward
outputs = self.net(inputs)
loss = self.criterion(outputs, inputs)
# backward + optimize
loss.backward()
optimizer.step()
```