forked from facebookresearch/ELF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval_lstm.py
46 lines (33 loc) · 1.27 KB
/
eval_lstm.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
# Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from datetime import datetime
import sys
import os
from rlpytorch import LSTMTrainer, Sampler, EvalIters, load_env, ModelLoader, ArgsProvider, ModelInterface
if __name__ == '__main__':
trainer = LSTMTrainer()
eval_iters = EvalIters()
env, all_args = load_env(os.environ, overrides=dict(actor_only=True), trainer=trainer, eval_iters=eval_iters)
GC = env["game"].initialize()
model = env["model_loaders"][0].load_model(GC.params)
mi = ModelInterface()
mi.add_model("model", model)
mi.add_model("actor", model, copy=True, cuda=all_args.gpu is not None, gpu_id=all_args.gpu)
trainer.setup(sampler=env["sampler"], mi=env["mi"])
def actor(batch):
reply = trainer.actor(batch)
eval_iters.stats.feed_batch(batch)
return reply
GC.reg_callback("actor", actor)
GC.Start()
trainer.episode_start(0)
for n in eval_iters.iters():
GC.Run()
GC.Stop()