import tensorflow as tf

        d_fake_logits=d_fake_logits)

    penalty_loss = penalty_lib.get_penalty_loss(
        x=images, x_fake=generated, y=y, is_training=is_training,
        discriminator=self.discriminator, architecture=self._architecture)
    self.d_loss += self._lambda * penalty_loss

    z_projs = tf.concat([z_projs_real, z_projs_fake], 0)
    z_aug_projs = tf.concat([z_aug_projs_real, z_aug_projs_fake], 0)

    sims_logits = tf.matmul(z_projs, z_aug_projs, transpose_b=True)
    logits_max = tf.reduce_max(sims_logits,1)
    sims_logits = sims_logits - tf.reshape(logits_max, [-1, 1])
    sims_probs = tf.nn.softmax(sims_logits)

    sim_labels = tf.constant(np.arange(bs * 2, dtype=np.int32))
    sims_onehot = tf.one_hot(sim_labels, bs * 2)

    c_real_loss = - tf.reduce_mean(
        tf.reduce_sum(sims_onehot * tf.log(sims_probs + 1e-10), 1))

    self.d_loss += c_real_loss * self._weight_contrastive_loss_d

    self._tpu_summary.scalar("loss/c_real_loss", c_real_loss)
    self._tpu_summary.scalar("loss/penalty", penalty_loss)

