Training Loss not decreasing (CIFAR10 Tutorials Example)

The loss is not decreasing after around 11 epochs. The model is a slight variant of the one in pytorch tutorial. It wasn’t working even for the tutorial’s model which I thought was because it was underfitting.

[10, 2000] loss: 0.873
[10, 4000] loss: 0.901
[10, 6000] loss: 0.890
[10, 8000] loss: 0.927
[10, 10000] loss: 0.910
[10, 12000] loss: 0.939
[11, 2000] loss: 0.828
[11, 4000] loss: 0.867
[11, 6000] loss: 0.883
[11, 8000] loss: 0.902
[11, 10000] loss: 0.917
[11, 12000] loss: 0.917
[12, 2000] loss: 0.818
[12, 4000] loss: 0.848
[12, 6000] loss: 0.883
[12, 8000] loss: 0.861
[12, 10000] loss: 0.871
[12, 12000] loss: 0.903
[13, 2000] loss: 0.799
[13, 4000] loss: 0.807
[13, 6000] loss: 0.864
[13, 8000] loss: 0.850
[13, 10000] loss: 0.888
[13, 12000] loss: 0.910
[14, 2000] loss: 0.777
[14, 4000] loss: 0.836
[14, 6000] loss: 0.843
[14, 8000] loss: 0.832
[14, 10000] loss: 0.863
[14, 12000] loss: 0.873
[15, 2000] loss: 0.759
[15, 4000] loss: 0.819
[15, 6000] loss: 0.817
[15, 8000] loss: 0.834
[15, 10000] loss: 0.847
[15, 12000] loss: 0.873
[16, 2000] loss: 0.756
[16, 4000] loss: 0.810
[16, 6000] loss: 0.830
[16, 8000] loss: 0.834
[16, 10000] loss: 0.860
[16, 12000] loss: 0.846
[17, 2000] loss: 0.762
[17, 4000] loss: 0.785
[17, 6000] loss: 0.811
[17, 8000] loss: 0.828
[17, 10000] loss: 0.849
[17, 12000] loss: 0.848
[18, 2000] loss: 0.779
[18, 4000] loss: 0.817
[18, 6000] loss: 0.793
[18, 8000] loss: 0.815
[18, 10000] loss: 0.852
[18, 12000] loss: 0.848
[19, 2000] loss: 0.739
[19, 4000] loss: 0.769
[19, 6000] loss: 0.816
[19, 8000] loss: 0.813
[19, 10000] loss: 0.834
[19, 12000] loss: 0.859
[20, 2000] loss: 0.738
[20, 4000] loss: 0.789
[20, 6000] loss: 0.826
[20, 8000] loss: 0.834
[20, 10000] loss: 0.867
[20, 12000] loss: 0.855
[21, 2000] loss: 0.772
[21, 4000] loss: 0.795
[21, 6000] loss: 0.793
[21, 8000] loss: 0.805
[21, 10000] loss: 0.834
[21, 12000] loss: 0.871
[22, 2000] loss: 0.757
[22, 4000] loss: 0.801
[22, 6000] loss: 0.831
[22, 8000] loss: 0.823
[22, 10000] loss: 0.840
[22, 12000] loss: 0.878
[23, 2000] loss: 0.771
[23, 4000] loss: 0.776
[23, 6000] loss: 0.811
[23, 8000] loss: 0.809
[23, 10000] loss: 0.844
[23, 12000] loss: 0.859

import torch
import torchvision
import torchvision.transforms as transforms
import torchvision.models as models

transform = transforms.Compose(
    [transforms.ToTensor(),
     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
                                        download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4,
                                          shuffle=True, num_workers=2)


testset = torchvision.datasets.CIFAR10(root='./data', train=False,
                                       download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=4,
                                         shuffle=False, num_workers=2)

classes = ('plane', 'car', 'bird', 'cat',
           'deer', 'dog', 'frog', 'horse', 'ship', 'truck')

import matplotlib.pyplot as plt
import numpy as np

# functions to show an image


def imshow(img):
    img = img / 2 + 0.5     # unnormalize
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))
    plt.show()


# get some random training images
dataiter = iter(trainloader)
images, labels = dataiter.next()

# show images
imshow(torchvision.utils.make_grid(images))
# print labels
print(' '.join('%5s' % classes[labels[j]] for j in range(4)))

import torch.nn as nn
import torch.nn.functional as F


class Net(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.conv3 = nn.Conv2d(16, 16, 5, padding=2)
        self.conv4 = nn.Conv2d(16,32, 5, padding=2)
        self.fc1 = nn.Linear(800, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84,67)

    def forward(self, x):
        x = self.pool(F.relu(self.conv1(x)))
        x = F.relu(self.conv2(x))
        x = F.relu(self.conv3(x))
        x = self.pool(F.relu(self.conv4(x)))
        x = x.view(-1,800)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x



net = Net()

import torch.optim as optim

criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)

for epoch in range(200):  # loop over the dataset multiple times

    running_loss = 0.0
    for i, data in enumerate(trainloader, 0):
        # get the inputs; data is a list of [inputs, labels]
        inputs, labels = data

        # zero the parameter gradients
        optimizer.zero_grad()

        # forward + backward + optimize
        outputs = net(inputs)
        loss = criterion(outputs, labels)
        loss.backward()
        optimizer.step()

        # print statistics
        running_loss += loss.item()
        if i % 2000 == 1999:    # print every 2000 mini-batches
            print('[%d, %5d] loss: %.3f' %
                  (epoch + 1, i + 1, running_loss / 2000))
            running_loss = 0.0
            

print('Finished Training')