-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_stacore.py
108 lines (78 loc) · 3.35 KB
/
run_stacore.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
from __future__ import division
import os
import json
import argparse
import numpy as np
import torch
from utils.args import stacore_parser
from tasks.stacore import STACoRe
from utils.mypath import mypath
from itertools import product
import warnings
warnings.filterwarnings(action='ignore')
def my_product(inp):
return (dict(zip(inp.keys(), values)) for values in product(*inp.values()))
def main(args: argparse, game_name: str = None, exp_num: int = None):
# Define Save Path
result_path = mypath(args, exp_num=exp_num)
args.game = game_name
xid = f'{args.game}-{str(args.seed)}'
args.id = xid
print(' ' * 26 + 'Options')
for k, v in vars(args).items():
print(' ' * 26 + k + ': ' + str(v))
results_dir = os.path.join(result_path, args.id)
if not os.path.exists(results_dir):
os.makedirs(results_dir)
# Save parameter argument dictionary
with open(os.path.join(results_dir, 'arg_parser.json'), 'w') as f:
json.dump(args.__dict__, f, indent=2)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed(args.seed)
torch.backends.cudnn.enabled = args.enable_cudnn
stacore = STACoRe(args, results_dir)
stacore.run_stacore()
if __name__ == '__main__':
parser = stacore_parser()
args = parser.parse_args()
game_list = ['alien', 'amidar', 'assault', 'asterix', 'bank_heist',
'battle_zone', 'boxing', 'breakout', 'chopper_command',
'crazy_climber', 'demon_attack', 'freeway', 'frostbite',
'gopher', 'hero', 'jamesbond', 'kangaroo', 'krull',
'kung_fu_master', 'ms_pacman', 'pong', 'private_eye',
'qbert', 'road_runner', 'seaquest', 'up_n_down']
experiments = list(np.random.randint(10000, size=10))
if args.ssl_option == 'none':
# Baseline
for i, exp_seed in enumerate(experiments):
args.seed = int(exp_seed)
args.stcl_option = 'stdim'
args.ucb_option = False
for game_name in game_list:
main(args, game_name, exp_num=int(i+1))
elif args.ssl_option == 'stacore':
# Proposed Method (quantile)
if args.threshold_option == 'quantile':
for i, exp_seed in enumerate(experiments):
args.seed = int(exp_seed)
args.stcl_option = 'stdim' # Change
args.ucb_option = True # Fix
args.num_threshold = 0.5 # Change
for game_name in game_list:
main(args, game_name, exp_num=int(i+1))
elif args.threshold_option == 'topk':
for i, exp_seed in enumerate(experiments):
args.seed = int(exp_seed)
args.stcl_option = 'stdim' # Fix
args.ucb_option = True # Fix
args.num_topk = 16 # Change
for game_name in game_list:
main(args, game_name, exp_num=int(i+1))
else:
for i, exp_seed in enumerate(experiments):
args.seed = int(exp_seed)
args.stcl_option = 'stdim' # Fix
args.ucb_option = True # Fix
for game_name in game_list:
main(args, game_name, exp_num=int(i+1))