import tensorflow as tf

    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)

