-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
28 lines (22 loc) · 868 Bytes
/
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
import torch
from models.resnet import ResNet, ResNet101
from models.vgg import VGG16
import torchvision.transforms as transforms
IMAGE_PREPROCESSING = transfor_img = transforms.Compose([
transforms.RandomCrop(32, padding=4),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010)),
])
CLASSES = ('plane', 'car', 'bird', 'cat', 'deer',
'dog', 'frog', 'horse', 'ship', 'truck')
def load_model(path: str, device: str):
if path.find("vgg"):
model = VGG16()
else:
model = ResNet101()
checkpoint = torch.load(path, map_location=torch.device(device))
model = ResNet101()
model.state_dict(checkpoint['net'])
model.eval()
return model, checkpoint['epoch'], checkpoint['acc'], checkpoint['loss'] # TODO: Add keyparam 'loss'