Hello!
I’ve built a CNN model which I’m now attempting to training using the conventional for-loop. I’ve been having an issue the past few days in which I’m not able to get the for-loop to work properly. Essentially, what happens is that the loop prints the epochs continuously until I have to interrupt.
This is the code I’m using:
epochs = 30
training_loss = []

for epoch in range(epochs):

    running_loss = 0

    #Train
    cnn.train()

    for images, labels in trainloader:
        if cuda:
            images, labels = images.cuda(), labels.cuda()

        optimiser.zero_grad()
        outputs = cnn(images)
        loss = criterion(outputs, labels)
        running_loss += loss.item() * images.size(0)
        loss.backward()
        optimiser.step()
    
        epochs_train_loss = running_loss / len(trainloader.dataset)
        print ("Epoch {}, Training Loss: {}".format(epoch, training_loss))

I’ve tried to place both
epochs_train_loss = running_loss / len(trainloader.dataset)
print ("Epoch {}, Training Loss: {}".format(epoch, training_loss)) 

out the for-loop but then nothing happens - the cell just runs indefinitely. I’m using a training set of 5000 images.