Plotting accuarcy and loss

Sara176: <p>I am working on my first project using pytorch , how can i plot accuracy and loss for the last epoch ?<br>
this is the code i am using</p>
<p>def train(model, dset_loaders, criterion, epoch, phase, optimizer, args, logger, use_gpu):</p>
<pre><code>model.train()

running_loss, running_corrects, running_all = 0., 0., 0.
for batch_idx, (inputs, targets) in enumerate(dset_loaders[phase]):
</code></pre>
<p><span class="hashtag">#inputs</span> shape: torch.Size([70, 29, 96, 96])<br>
<span class="hashtag">#targets</span> shape: torch.Size([70])<br>
batch_img = RandomCrop(inputs.numpy(), (88, 88))<br>
batch_img = ColorNormalize(batch_img)<br>
batch_img = HorizontalFlip(batch_img)</p>
<pre><code>    batch_img = np.reshape(batch_img, (batch_img.shape[0], batch_img.shape[1], batch_img.shape[2], batch_img.shape[3], 1))
    
    inputs = torch.from_numpy(batch_img)
    
    inputs = inputs.float().permute(0, 4, 1, 2, 3).contiguous()
    
    
    outputs = model(inputs)
    
    _, preds = torch.max(outputs.data, 1)
    loss = criterion(outputs, targets)
    #Backward
    optimizer.zero_grad()
    loss.backward()
    #Optimizing step
    optimizer.step()
    # stastics
    running_loss += loss.item() * inputs.size(0) #running_loss += loss.item() * now_batch_size
    batch_correct = (preds == targets.data).sum().item()
    running_corrects += batch_correct
    running_all += len(inputs)
   
loss_epoch =  float(running_loss) / len(dset_loaders[phase].dataset)
acc_epoch = float(running_corrects) / len(dset_loaders[phase].dataset)
</code></pre>
<p>def test(model, dset_loaders, criterion, epoch, phase, args, logger, use_gpu, save=True):</p>
<pre><code>model.eval()
with torch.no_grad():

    running_loss, running_corrects, running_all = 0., 0., 0.
 
    for batch_idx, (inputs, targets) in enumerate(dset_loaders[phase]):

        batch_img = CenterCrop(inputs.numpy(), (88, 88))
        batch_img = ColorNormalize(batch_img)

        batch_img = np.reshape(batch_img, (batch_img.shape[0], batch_img.shape[1], batch_img.shape[2], batch_img.shape[3], 1))
        inputs = torch.from_numpy(batch_img)
        inputs = inputs.float().permute(0, 4, 1, 2, 3).contiguous()
       
        outputs = model(inputs)

        _, preds = torch.max(outputs.data, 1)
        loss = criterion(outputs, targets)
        # stastics
        running_loss += loss.data * inputs.size(0)
        running_corrects += (preds == targets.data).sum().item()
        running_all += len(inputs)
      
    loss_epoch = float(running_loss) / len(dset_loaders[phase].dataset)
    acc_epoch = float(running_corrects) / len(dset_loaders[phase].dataset)
   
if save:
    return acc_epoch
</code></pre>
<p>def test_adam(args, use_gpu):</p>
<pre><code>net = CNN3D()
print(net)
# reload model
reload_model(net, logger, args.path)
# define loss function and optimizer
model = torch.nn.DataParallel(net)

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(net.parameters(), lr=args.lr, weight_decay=5e-5, amsgrad=True)

dset_loaders, dset_sizes = data_loader(args)
if args.test:
    test(model, dset_loaders, criterion, 0, 'test',  args, logger, use_gpu,  False)
    return

best_acc = -1
for epoch in range(args.s_epochs, args.epochs):
    train(model, dset_loaders, criterion, epoch, 'train', optimizer, args, logger, use_gpu)
    test_acc = test(model, dset_loaders, criterion, 0, 'val', args, logger, use_gpu, True)
    if test_acc &gt; best_acc:
        best_acc = max(test_acc, best_acc)
        state_dict = net.state_dict()
        torch.save(state_dict, '{}/epoch{}_acc{}.pt'.format(save_path,str(epoch),str(best_acc)))
</code></pre>
<p>if <strong>name</strong> == ‘<strong>main</strong>’:<br>
use_gpu = torch.cuda.is_available()<br>
test_adam(args, use_gpu)</p>