code: def build_graph(self, comb_state, action, reward, isOver):
      comb_state = tf.cast(comb_state, tf.float32)
      input_rank = comb_state.shape.rank
  
      state = tf.slice(
          comb_state,
          [0] * input_rank,
          [-1] * (input_rank - 1) + [self.history],
          name="state",
      )
  
      self.predict_value = self.get_DQN_prediction(state)
      if not self.training:
          return
  
      reward = tf.clip_by_value(reward, -1, 1)
      next_state = tf.slice(
          comb_state,
          [0] * (input_rank - 1) + [1],
          [-1] * (input_rank - 1) + [self.history],
          name="next_state",
      )
      next_state = tf.reshape(next_state, self._stacked_state_shape)
      action_onehot = tf.one_hot(action, self.num_actions, 1.0, 0.0)
  
      pred_action_value = tf.reduce_sum(
          self.predict_value * action_onehot, 1
      )  # N,
      max_pred_reward = tf.reduce_mean(
          tf.reduce_max(self.predict_value, 1), name="predict_reward"
      )
      summary.add_moving_summary(max_pred_reward)
  
      with tf.variable_scope("target"), varreplace.freeze_variables(
          skip_collection=True
      ):
          targetQ_predict_value = self.get_DQN_prediction(
              next_state
          )  # NxA
  
      if self.method != "Double":
          # DQN
          best_v = tf.reduce_max(targetQ_predict_value, 1)  # N,
      else:
          # Double-DQN
          next_predict_value = self.get_DQN_prediction(next_state)
          self.greedy_choice = tf.argmax(next_predict_value, 1)  # N,
          predict_onehot = tf.one_hot(
              self.greedy_choice, self.num_actions, 1.0, 0.0
          )
          best_v = tf.reduce_sum(
              targetQ_predict_value * predict_onehot, 1
          )
  
      target = reward + (
          1.0 - tf.cast(isOver, tf.float32)
      ) * self.gamma * tf.stop_gradient(best_v)
  
      cost = tf.losses.huber_loss(
          target, pred_action_value, reduction=tf.losses.Reduction.MEAN
      )
      summary.add_param_summary(
          ("conv.*/W", ["histogram", "rms"]),
          ("fc.*/W", ["histogram", "rms"]),
      )  # monitor all W
      summary.add_moving_summary(cost)
      return cost
  
file_path: tensorpack/examples/DeepQNetwork/DQNModel.py
imports: import abc
  from tensorpack import ModelDesc
  from tensorpack.compat import tfv1
  from tensorpack.tfutils import gradproc, optimizer, summary, varreplace
  from tensorpack.tfutils.scope_utils import auto_reuse_variable_scope
  from tensorpack.utils import logger
label_desc: Use image node_id 5 for calling the Model obj's underlying member method code with example usage: obj.build_graph(comb_state, action, reward, isOver) and returns: cost