-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
54 lines (46 loc) · 1.41 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pandas as pd
import os
import glob
from PIL import Image
import matplotlib.pyplot as plt
import torch
def plot(loss_p,acc_p,epochs):
x = [i for i in range(epochs)]
plt.plot(x,loss_p['train'],color='red', marker='o')
plt.title('Train loss')
plt.xlabel('epochs')
plt.ylabel('loss')
plt.grid(True)
plt.savefig('/content/train_loss.png')
plt.clf()
plt.plot(x, loss_p['val'],color='red', marker='o')
plt.title('Val loss')
plt.xlabel('epochs')
plt.ylabel('loss')
plt.grid(True)
plt.savefig('/content/val_loss.png')
plt.clf()
#acc
plt.plot(x, acc_p['train'],color='red', marker='o')
plt.title('Train acc')
plt.xlabel('epochs')
plt.ylabel('acc')
plt.grid(True)
plt.savefig('/content/train_acc.png')
plt.clf()
plt.plot(x, acc_p['val'],color='red', marker='o')
plt.title('Val acc')
plt.xlabel('epochs')
plt.ylabel('acc')
plt.grid(True)
plt.savefig('/content/val_acc.png')
plt.clf()
def save_ckp(state, checkpoint_path):
f_path = checkpoint_path
torch.save(state, f_path)
def load_ckp(checkpoint_fpath, model, optimizer, device):
checkpoint = torch.load(checkpoint_fpath,map_location=device)
model.load_state_dict(checkpoint['state_dict'])
optimizer.load_state_dict(checkpoint['optimizer'])
valid_acc = checkpoint['valid_acc']
return model, optimizer, checkpoint['epoch'], valid_acc