-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
35 lines (28 loc) · 924 Bytes
/
run.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
import os
from utils.cli_parser import arg_parser
from es.wrapper import EvolutionaryStrategyWrapper
def main():
args = arg_parser().parse_args()
agent = EvolutionaryStrategyWrapper(args)
# load existing weights if specified
if args.weights_file != '':
agent.load(args.weights_file)
# render environment if specified
if args.render:
agent.render()
else:
if not os.path.exists('weights'):
os.makedirs('weights')
path = os.path.join('weights', 'env_{}_model_{}.pkl'.format(args.env, args.model))
# run until end of iterations
try:
agent.train(args.num_iters)
# catch early exit from training
except KeyboardInterrupt:
print("Saving weights...")
agent.save(path)
return
print("Saving weights...")
agent.save(path)
if __name__ == '__main__':
main()