Tensorflow2.0 有没有办法在Tensorflow中用矩阵跟踪两个向量的洗牌?

Tensorflow2.0 有没有办法在Tensorflow中用矩阵跟踪两个向量的洗牌?,tensorflow2.0,Tensorflow2.0,我试图实现一个对比损失函数,其中我有两批增强图像,其中batch1[i]和batch2[i]来自同一个图像。然而,如果我不洗牌,网络将学习生成一个单位矩阵,因此我尝试了洗牌,但我无法在tensorflow中计算新的单位矩阵。我试图通过以下方式实现它,但tensorflow不会在图形模式下执行numpy函数,因此我需要一个tensorflow解决方案: hidden1 = tf.random.normal((24,128)) # Actually outputs of NN hidden2 =

我试图实现一个对比损失函数,其中我有两批增强图像,其中batch1[i]和batch2[i]来自同一个图像。然而,如果我不洗牌,网络将学习生成一个单位矩阵,因此我尝试了洗牌,但我无法在tensorflow中计算新的单位矩阵。我试图通过以下方式实现它,但tensorflow不会在图形模式下执行numpy函数,因此我需要一个tensorflow解决方案:

hidden1 = tf.random.normal((24,128)) # Actually outputs of NN 
hidden2 = tf. random.normal((24,128))

batch_size = 24

labels = tf.one_hot(tf.range(batch_size), batch_size) # Identity matrix of hidden1, hidden2 to know which augmentations came from the same Image input

shuffle_a = tf.random.shuffle(tf.range(0, batch_size, dtype=tf.int32))
shuffle_b = tf.random.shuffle(tf.range(0, batch_size, dtype=tf.int32))

hidden1 = tf.gather(hidden1, shuffle_a) 
hidden2 = tf.gather(hidden2, shuffle_b)

labels_new = np.zeros((24,24)) 
labels_new[shuffle_a, shuffle_b] = 1
#Heres the Problem: I dont know how to compute this matrix labels_new in Tensorflow

我真的很感激一些有用的提示。这可能是我错过的很简单的东西