-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain_eval.py
executable file
·132 lines (110 loc) · 3.88 KB
/
main_eval.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from __future__ import print_function, division
import os
os.environ["OMP_NUM_THREADS"] = "1"
import torch
import torch.multiprocessing as mp
import time
import numpy as np
import random
import json
from tqdm import tqdm
from utils.net_util import ScalarMeanTracker
from runners import nonadaptivea3c_val, savn_val
def main_eval(args, create_shared_model, init_agent):
np.random.seed(args.seed)
torch.manual_seed(args.seed)
random.seed(args.seed)
if args.gpu_ids == -1:
args.gpu_ids = [-1]
else:
torch.cuda.manual_seed(args.seed)
try:
mp.set_start_method("spawn")
except RuntimeError:
pass
model_to_open = args.load_model
processes = []
res_queue = mp.Queue()
if args.model == "SAVN":
args.learned_loss = True
args.num_steps = 6
target = savn_val
else:
args.learned_loss = False
args.num_steps = 50
target = nonadaptivea3c_val
rank = 0
for scene_type in args.scene_types:
p = mp.Process(
target=target,
args=(
rank,
args,
model_to_open,
create_shared_model,
init_agent,
res_queue,
250,
scene_type,
),
)
p.start()
processes.append(p)
time.sleep(0.1)
rank += 1
count = 0
end_count = 0
train_scalars = ScalarMeanTracker()
train_scalars_ba = ScalarMeanTracker()
train_scalars_be = ScalarMeanTracker()
train_scalars_k = ScalarMeanTracker()
train_scalars_l = ScalarMeanTracker()
proc = len(args.scene_types)
pbar = tqdm(total=250 * proc)
try:
while end_count < proc:
train_result = res_queue.get()
pbar.update(1)
count += 1
if (args.scene_types[end_count] == 'bathroom'):
train_scalars_ba.add_scalars(train_result)
if (args.scene_types[end_count] == 'bedroom'):
train_scalars_be.add_scalars(train_result)
if (args.scene_types[end_count] == 'kitchen'):
train_scalars_k.add_scalars(train_result)
if (args.scene_types[end_count] == 'living_room'):
train_scalars_l.add_scalars(train_result)
if "END" in train_result:
end_count += 1
continue
train_scalars.add_scalars(train_result)
tracked_means = train_scalars.pop_and_reset()
tracked_means_ba = train_scalars_ba.pop_and_reset()
tracked_means_be = train_scalars_be.pop_and_reset()
tracked_means_k = train_scalars_k.pop_and_reset()
tracked_means_l = train_scalars_l.pop_and_reset()
finally:
for p in processes:
time.sleep(0.1)
p.join()
with open(args.results_json, "w") as fp:
json.dump(tracked_means, fp, sort_keys=True, indent=4)
# with open('all_data_'+args.results_json, "a+") as f:
# json.dump(args.load_model, f)
# json.dump(tracked_means, f, sort_keys=True, indent=4)
if(args.room_results):
with open('all_data_ba_'+args.results_json, "a+") as f:
json.dump(args.load_model, f)
json.dump(tracked_means_ba, f, sort_keys=True, indent=4)
if(args.room_results):
with open('all_data_be_'+args.results_json, "a+") as f:
json.dump(args.load_model, f)
json.dump(tracked_means_be, f, sort_keys=True, indent=4)
if(args.room_results):
with open('all_data_k_'+args.results_json, "a+") as f:
json.dump(args.load_model, f)
json.dump(tracked_means_k, f, sort_keys=True, indent=4)
if(args.room_results):
with open('all_data_l_'+args.results_json, "a+") as f:
json.dump(args.load_model, f)
json.dump(tracked_means_l, f, sort_keys=True, indent=4)