import tensorflow as tf



def contra_step_lossV5(pred, tgt, resample=1):
    # p = tf.print('begin loss v5', [resample, pred.shape,tgt.shape])
    # with tf.control_dependencies([p]):
    pred_flat = tf.reshape(pred, [-1])
    tgt_flat = tf.reshape(tgt, [-1])
    batch = tf.stack([pred_flat, tgt_flat], 1)
    num_sam = tools.shape(batch)[0]
    index = tf.range(num_sam)
    divider = tf.constant(resample, dtype=tf.float32)

    def sample_compute(cur_loss, i):
        batch1 = tf.gather(batch, tf.random.shuffle(index))
