(action_set, level_names)
Test.
Test.
Test .
def test(action_set, level_names):
  """Test."""

  level_returns = {level_name: [] for level_name in level_names}
  with tf.Graph().as_default():
    agent = Agent(len(action_set))
    outputs = {}
    for level_name in level_names:
      env = create_environment(level_name, seed=1, is_test=True)
      outputs[level_name] = build_actor(agent, env, level_name, action_set)

    with tf.train.SingularMonitoredSession(
        checkpoint_dir=FLAGS.logdir,
        hooks=[py_process.PyProcessHook()]) as session:
      for level_name in level_names:
        tf.logging.info('Testing level: %s', level_name)
        while True:
          done_v, infos_v = session.run((
              outputs[level_name].env_outputs.done,
              outputs[level_name].env_outputs.info
          ))
          returns = level_returns[level_name]
          returns.extend(infos_v.episode_return[1:][done_v[1:]])

          if len(returns) >= FLAGS.test_num_episodes:
            tf.logging.info('Mean episode return: %f', np.mean(returns))
            break

  if FLAGS.level_name == 'dmlab30':
    no_cap = dmlab30.compute_human_normalized_score(level_returns,
                                                    per_level_cap=None)
    cap_100 = dmlab30.compute_human_normalized_score(level_returns,
                                                     per_level_cap=100)
    tf.logging.info('No cap.: %f Cap 100: %f', no_cap, cap_100)
def test ( action_set , level_names ) : level_returns = { level_name : [ ] for level_name in level_names } with tf . Graph ( ) . as_default ( ) : agent = Agent ( len ( action_set ) ) outputs = { } for level_name in level_names : env = create_environment ( level_name , seed = 1 , is_test = True ) outputs [ level_name ] = build_actor ( agent , env , level_name , action_set ) with tf . train . SingularMonitoredSession ( checkpoint_dir = FLAGS . logdir , hooks = [ py_process . PyProcessHook ( ) ] ) as session : for level_name in level_names : tf . logging . info ( 'Testing level: %s' , level_name ) while True : done_v , infos_v = session . run ( ( outputs [ level_name ] . env_outputs . done , outputs [ level_name ] . env_outputs . info ) ) returns = level_returns [ level_name ] returns . extend ( infos_v . episode_return [ 1 : ] [ done_v [ 1 : ] ] ) if len ( returns ) >= FLAGS . test_num_episodes : tf . logging . info ( 'Mean episode return: %f' , np . mean ( returns ) ) break if FLAGS . level_name == 'dmlab30' : no_cap = dmlab30 . compute_human_normalized_score ( level_returns , per_level_cap = None ) cap_100 = dmlab30 . compute_human_normalized_score ( level_returns , per_level_cap = 100 ) tf . logging . info ( 'No cap.: %f Cap 100: %f' , no_cap , cap_100 )