class_docstr: Train and evaluate DQN on Atari.
class_docstr_tok: ["Train","and","evaluate","DQN","on","Atari","."]
docstr: Execute the train/eval loop.
docstr_tok: ["Execute","the","train\/eval","loop","."]
code: def run(self):
      """Execute the train/eval loop."""
      with tf.compat.v1.Session(
          config=tf.compat.v1.ConfigProto(allow_soft_placement=True)
      ) as sess:
          # Initialize the graph.
          self._initialize_graph(sess)
  
          # Initial collect
          self._initial_collect()
  
          while self._iteration_metric.result() < self._num_iterations:
              # Train phase
              env_steps = 0
              for metric in self._train_phase_metrics:
                  metric.reset()
              while env_steps < self._train_steps_per_iteration:
                  env_steps += self._run_episode(
                      sess,
                      self._train_metrics + self._train_phase_metrics,
                      train=True,
                  )
              for metric in self._train_phase_metrics:
                  log_metric(metric, prefix="Train/Metrics")
              py_metric.run_summaries(
                  self._train_phase_metrics + [self._iteration_metric]
              )
  
              global_step_val = sess.run(self._global_step)
  
              if self._do_eval:
                  # Eval phase
                  env_steps = 0
                  for metric in self._eval_metrics:
                      metric.reset()
                  while env_steps < self._eval_steps_per_iteration:
                      env_steps += self._run_episode(
                          sess, self._eval_metrics, train=False
                      )
  
                  py_metric.run_summaries(
                      self._eval_metrics + [self._iteration_metric]
                  )
                  if self._eval_metrics_callback:
                      results = dict(
                          (metric.name, metric.result())
                          for metric in self._eval_metrics
                      )
                      self._eval_metrics_callback(
                          results, global_step_val
                      )
                  for metric in self._eval_metrics:
                      log_metric(metric, prefix="Eval/Metrics")
  
              self._iteration_metric()
  
              self._train_checkpointer.save(global_step=global_step_val)
              self._policy_checkpointer.save(
                  global_step=global_step_val
              )
              self._rb_checkpointer.save(global_step=global_step_val)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl import app
  from absl import flags
  from absl import logging
  import gin
  import numpy
  import tensorflow
  from tf_agents.agents.categorical_dqn import categorical_dqn_agent
  from tf_agents.environments import batched_py_environment
  from tf_agents.environments import suite_atari
  from tf_agents.eval import metric_utils
  from tf_agents.metrics import py_metric
  from tf_agents.metrics import py_metrics
  from tf_agents.networks import categorical_q_network
  from tf_agents.networks import network
  from tf_agents.policies import epsilon_greedy_policy
  from tf_agents.policies import py_tf_policy
  from tf_agents.policies import random_py_policy
  from tf_agents.replay_buffers import py_hashed_replay_buffer
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.utils import common
  from tf_agents.utils import timer
label_desc: Use image node_id 3 for calling the TrainEval obj's underlying member method code with example usage: obj.run() without return types