-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathvalidation.py
52 lines (45 loc) · 1.67 KB
/
validation.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
import os
import tqdm
import torch
import torch.nn as nn
import torch.nn.functional as F
import argparse
import torchvision.transforms as transforms
from torchvision import datasets
from model.model import RandWire
from utils.hparams import HParam
from utils.graph_reader import read_graph
from utils.evaluation import validate
from dataset.dataloader import create_dataloader, MNIST_dataloader, CIFAR10_dataloader
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', type=str, required=True,
help="yaml file for configuration")
parser.add_argument('-p', '--checkpoint_path', type=str, default=None, required=False,
help="path of checkpoint pt file")
args = parser.parse_args()
hp = HParam(args.config)
graphs = [
read_graph(hp.model.graph0),
read_graph(hp.model.graph1),
read_graph(hp.model.graph2),
]
print('Loading model from checkpoint...')
model = RandWire(hp, graphs).cuda()
checkpoint = torch.load(args.checkpoint_path)
model.load_state_dict(checkpoint['model'])
step = checkpoint['step']
dataset = hp.data.type
switcher = {
'MNIST': MNIST_dataloader,
'CIFAR10':CIFAR10_dataloader,
'ImageNet':create_dataloader,
}
assert dataset in switcher.keys(), 'Dataset type currently not supported'
dl_func = switcher[dataset]
valset = dl_func(hp, args, False)
print('Validating...')
test_avg_loss, accuracy = validate(model, valset)
print('Result on step %d:' % step)
print('Average test loss: %.4f' % test_avg_loss)
print('Accuracy: %.3f' % accuracy)