Hello, am trying to draw graph of training loss and validation loss using matplotlip.pyplot but i usually get black graph.
my code is like this
plt.plot(train_loss, label=‘Training loss’)
plt.plot(valid_loss, label=‘Validation loss’)
plt.legend(frameon=False)
and the code which produce those loss value is
n_epochs = 30
valid_loss_min = np.Inf
for epochs in range(1, n_epochs+1):
train_loss = 0.0
valid_loss = 0.0

model.train()
for images, labels in train_loader:
    optimizer.zero_grad()
    output = model(images)
    loss = criterion(output,labels)
    loss.backward()
    optimizer.step()
    
    
    train_loss += loss.item()
    
model.eval()
for images, labels in valid_loader:
    output = model(images)
    loss = criterion(output,labels)
    
    valid_loss += loss.item()
train_loss = train_loss/len(train_loader.dataset)
valid_loss = valid_loss/len(valid_loader.dataset)

print('Epoch:  {}. Training Loss: {:.6f}. Validation_loss: {:.6f}'.format(epochs,train_loss,valid_loss))

if valid_loss <= valid_loss_min:
    print( 'Varidation Loss is decrease: ( {:.6f} -->{:.6f}). save the model...'.format(valid_loss_min, valid_loss))
    torch.save(model.state_dict(), 'mlp2_model.pt')
    valid_loss_min = valid_loss