If I remember correctly, I did something like this:
    losses = []
    for epoch in range(num_epochs):
        running_loss = 0.0
        for data in dataLoader:
            images, labels = data
            
            outputs = model(images)
            loss = criterion_label(outputs, labels)
            optimizer.zero_grad()
            loss.backward()
            optimizer.step()

            running_loss += loss.item() * images.size(0) 

        epoch_loss = running_loss / len(dataloaders['train'])
        losses.append(epoch_loss)

Let me know if this helps. It’s based on the solution the suggestion made by ptrblck in this post.