from tensorflow.python.ops import control_flow_ops

    if update_ops is None:
      update_ops = global_update_ops
    else:
      update_ops = set(update_ops)
    # Make sure update_ops are computed before total_loss.
    if update_ops:
      with tf.control_dependencies(update_ops):
        barrier = tf.no_op(name='update_barrier')
        self.d_losses[-1] = control_flow_ops.with_dependencies([barrier], self.d_losses[-1])
        self.g_losses[-1] = control_flow_ops.with_dependencies([barrier], self.g_losses[-1])
        self.d_loss_real = control_flow_ops.with_dependencies([barrier], self.d_loss_real)
        self.d_loss_fake = control_flow_ops.with_dependencies([barrier], self.d_loss_fake)
        self.d_loss_class = control_flow_ops.with_dependencies([barrier], self.d_loss_class)
    t_vars = self._get_vars_semi_supervised()
    if self.clip_by_global_norm:
      self.capped_d_grads = self._clip_grad_global_norms(
          t_vars['d_vars'], self.d_losses[-1], d_optimizer, gradient_noise_scale=0.0)
      self.capped_g_grads = self._clip_grad_global_norms(
