-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
73 lines (60 loc) · 2.5 KB
/
main.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
"""
### NOTICE ###
You DO NOT need to upload this file
"""
import argparse
from test import test
from environment import Environment
def parse():
parser = argparse.ArgumentParser(description="MLDS&ADL HW3")
parser.add_argument('--env_name', default=None, help='environment name')
parser.add_argument('--train_pg', action='store_true', help='whether train policy gradient')
parser.add_argument('--train_dqn', action='store_true', help='whether train DQN')
parser.add_argument('--train_mario', action='store_true', help='whether train mario')
parser.add_argument('--test_pg', action='store_true', help='whether test policy gradient')
parser.add_argument('--test_dqn', action='store_true', help='whether test DQN')
parser.add_argument('--test_mario', action='store_true', help='whether test mario')
parser.add_argument('--video_dir', default=None, help='output video directory')
parser.add_argument('--do_render', action='store_true', help='whether render environment')
try:
from argument import add_arguments
parser = add_arguments(parser)
except:
pass
args = parser.parse_args()
return args
def run(args):
if args.train_pg:
env_name = args.env_name or 'LunarLander-v2'
env = Environment(env_name, args, atari_wrapper=False)
from agent_dir.agent_pg import AgentPG
agent = AgentPG(env, args)
agent.train()
if args.train_dqn:
env_name = args.env_name or 'AssaultNoFrameskip-v0'
env = Environment(env_name, args, atari_wrapper=True)
from agent_dir.agent_dqn import AgentDQN
agent = AgentDQN(env, args)
agent.train()
if args.train_mario:
from agent_dir.agent_mario import AgentMario
agent = AgentMario(None, args)
agent.train()
if args.test_pg:
env = Environment('LunarLander-v2', args, test=True)
from agent_dir.agent_pg import AgentPG
agent = AgentPG(env, args)
test(agent, env, total_episodes=30)
if args.test_dqn:
env = Environment('AssaultNoFrameskip-v0', args, atari_wrapper=True, test=True)
from agent_dir.agent_dqn import AgentDQN
agent = AgentDQN(env, args)
test(agent, env, total_episodes=100)
if args.test_mario:
env = Environment('SuperMarioBros-v0', args)
from agent_dir.agent_mario import AgentMario
agent = AgentMario(env, args)
test(agent, env, total_episodes=10)
if __name__ == '__main__':
args = parse()
run(args)