def make_agent_env(spec, global_nets=None): '''Helper to create agent and env given spec''' env = make_env(spec) body = Body(env, spec['agent']) AgentClass = getattr(agent_module, ps.get(spec['agent'][0], 'name')) agent = AgentClass(spec, body=body, global_nets=global_nets) return agent, env
def __init__(self, spec, global_nets=None): self.spec = spec self.index = self.spec['meta']['session'] util.set_random_seed(self.spec) util.set_cuda_id(self.spec) util.set_logger(self.spec, logger, 'session') spec_util.save(spec, unit='session') self.agent, self.env = make_agent_env(self.spec, global_nets) with util.ctx_lab_mode('eval'): # env for eval self.eval_env = make_env(self.spec) self.agent.body.eval_env = self.eval_env self.num_eval = ps.get(self.agent.spec, 'meta.num_eval') self.warmup_epi = ps.get(self.agent.agent_spec, 'algorithm.warmup_epi') or -1 logger.info(util.self_desc(self))
os.environ['lab_mode'] = 'eval' spec_file = sys.argv[1] spec_name = sys.argv[2] lab_mode = sys.argv[3] if '@' in lab_mode: lab_mode, prename = lab_mode.split('@') spec = spec_util.get_eval_spec(spec_file, spec_name, prename) else: spec = spec_util.get(spec_file, spec_name) # # lab_mode, prename = sys.argv[3].split('@') # spec = spec_util.get_eval_spec(spec_file, prename) spec = spec_util.override_eval_spec(spec) agent_spec = spec['agent'][0] env = make_env(spec) body = Body(env, spec['agent']) agent = DialogAgent(spec, body) # last_obs = 'hi' # agent.reset(last_obs) # obs = 'hi can you find me a hotel in the west?' # action = agent.act(obs) # next_obs = 'we have six people' # agent.update(obs, action, 0, next_obs, 0) # action = agent.act(next_obs) @app.route('/', methods=['GET', 'POST'])