Here is the code for training the neural network; if you cannot see it properly in the above images:

import time
start_time = time.time()
epochs = 5
train_losses = []
test_losses = []
train_correct = []
test_correct = []
for i in range(epochs):
trn_corr = 0
tst_corr = 0
#Running the batches
for b,(X_train,y_train) in enumerate(train_dataloader):
b+=1

#Apply the model

y_pred = model(X_train)

loss = criterion(y_pred,y_train)

#Tally the number of correct predictions

predicted = torch.max(y_pred.data,1)[1]

batch_corr = (predicted==y_train).sum()

trn_corr += batch_corr

#Update paramters

optimizer.zero_grad()

loss.backward()

optimizer.step()

#Print interim results

if b%100 == 0:

  print(f'epoch: {i:2}  batch: {b:4} [{10*b:6}/50000] loss:{loss.item():10.8f}\ accuracy: {trn_corr.item()*100/(10*b):7.3f}%')

train_losses.append(loss)
train_correct.append(trn_corr)