-
Notifications
You must be signed in to change notification settings - Fork 6
/
run_task_interference.py
163 lines (125 loc) · 4.13 KB
/
run_task_interference.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
import torch
import numpy as np
from smart_home_dataset import SmartHomeDataset
from classifier import Classifier
from torch import optim
import utils
import callbacks as cb
import time
from generative_replay_learner import GenerativeReplayLearner;
import arg_params
import json
import os
import copy
import torch.multiprocessing as mp
from run_main import *
def select_hidden_unit(args, cmd):
if args.data_dir == "pamap":
h = 1000
args.hidden_units = h
elif args.data_dir == "dsads":
h = 1000
args.hidden_units = h
elif args.data_dir == "housea":
h = 200
args.hidden_units = h
else:
h = 500
args.hidden_units = h
return args.hidden_units
if __name__ == "__main__":
parser = arg_params.get_parser()
args = parser.parse_args()
print("Arguments")
print(args)
result_folder = args.results_dir
print("\n")
print("STEP1: load datasets")
base_dataset = select_dataset(args)
methods = [("sg-cgan", 0)]
jobs = []
# pool = mp.Pool()
start = time.time()
ntask = 2
tasks = [
[
"R2_prepare_dinner",
"R2_watch_TV",
"R2_prepare_lunch",
"R1_work_at_dining_room_table",
],
[
"R2_prepare_lunch",
"R2_prepare_dinner",
"R1_work_at_dining_room_table",
"R2_watch_TV",
],
# [
# "R2_prepare_dinner",
# "R2_watch_TV",
# ],
# [
# "R2_prepare_lunch",
# "R1_work_at_dining_room_table",
# ],
# [
# "R2_prepare_dinner",
# "R2_prepare_lunch"
# ],
# [
# "R2_watch_TV",
# "R1_work_at_dining_room_table",
# ],
]
if args.task_order is not None:
ft = open(args.task_order)
tasks = [line.strip().split(";") for line in ft]
base_args = args
for task_order in range(len(tasks)):
base_dataset.permu_task_order(tasks[task_order])
args.tasks = len(tasks[task_order])//2
identity = {
"task_order": None,
"method": None,
"train_session": None,
"task_index": None,
"no_of_test": None,
"no_of_correct_prediction": None,
"accuracy": None,
"solver_training_time": None,
"generator_training_time": None,
}
identity["task_order"] = task_order
traindata, testdata = base_dataset.train_test_split()
for c in testdata.pddata["ActivityName"].unique():
d = testdata.pddata
print (c, len(d[d["ActivityName"]==c]))
dataset = traindata
if args.oversampling:
dataset = traindata.resampling()
train_datasets, config, classes_per_task = dataset.split(tasks=args.tasks)
test_datasets, _, _ = testdata.split(tasks=args.tasks)
test_datasets_per_class, _, _ = testdata.split(tasks=len(tasks[task_order]))
print("\n\nTraining Data")
for t in train_datasets:
print(t, len(t), t.pddata["ActivityName"].unique())
print("******* Run ",task_order,"*******")
print("\n")
# for t in train_datasets:
# print(t.classes, args.tasks, taskoooo[task_order])
for method in methods:
m, cmd = method
identity["method"] = m
args = copy.deepcopy(base_args)
args.critic_fc_units = select_hidden_unit(args, cmd)
args.generator_fc_units = select_hidden_unit(args, cmd)
args.g_iters = get_g_iter(m, None)
model = run_model(identity, method, args, config, train_datasets, test_datasets, True)
print("\nManual test")
for t in test_datasets_per_class:
print(t, len(t), t.pddata["ActivityName"].unique())
result = model.test(None, test_datasets_per_class, verbose=True)
training_time = time.time() - start
print(training_time)
# clearup_tmp_file(result_folder, ntask, methods)