-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyze_results.py
62 lines (49 loc) · 2.52 KB
/
analyze_results.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
55
56
57
58
59
from helper_classes import *
from Transformer.transformer_trainer import *
from HPO_RL import *
from tqdm import tqdm
import os
from constants import *
max_layers = 6
batch_size = 16
size_buffer = batch_size * 30
train_loader = torch.utils.data.DataLoader(
torchvision.datasets.MNIST({MNIST_FILE_LOCAL}, train=True, download = True,
transform = torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(
(0.1307,), (0.3081,)
)
])),
batch_size = batch_size, shuffle=False
)
test_loader = torch.utils.data.DataLoader(
torchvision.datasets.MNIST({MNIST_FILE_LOCAL}, train=False, download = True,
transform = torchvision.transforms.Compose([
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(
(0.1307,), (0.3081,)
)
])),
batch_size = batch_size, shuffle=False
)
experiment_nb = 1
os.makedirs(f"{RESULTS_DIR}/exp{experiment_nb}", exist_ok=True)
os.makedirs(f"{RESULTS_DIR}/exp{experiment_nb}/final_results", exist_ok=True)
os.makedirs(f"{RESULTS_DIR}/exp{experiment_nb}/figures", exist_ok=True)
rlhpo = RLHPO(max_layers=max_layers, experiment_number=experiment_nb)
rlhpo.train_loader = train_loader
rlhpo.test_loader = test_loader
rlhpo.is_testing = True
for i in tqdm(np.arange(900,980, 10)):
state_encoder = StateEncoding(action_space= 4, perf_space=32, output_layer=64)
state_encoder.load_state_dict(torch.load(f'{MODELS_DIR}/exp{experiment_nb}/EP-{i}_state_encoder.pt'))
state_encoder.eval()
transformer_trainer = TransformerTrainer(max_layers, 64, num_layers=2,
expansion_factor=4, n_heads=4, action_space=4, size_buffer = size_buffer,
env = rlhpo, target_episode = 75, state_encoder = state_encoder, training_loader=train_loader,
testing_loader=test_loader, saving_dir=f"{RESULTS_DIR}/exp{experiment_nb}")
transformer_trainer.eval()
transformer_trainer.load_models(f'{MODELS_DIR}/exp{experiment_nb}/EP-{i}')
transformer_trainer.eval()
rlhpo.eval(i, state_encoder, transformer_trainer)