简体   繁体   English

如何在张量流中打乱张量? 错误:没有为“ RandomShuffle”操作定义梯度

[英]How to shuffle tensor in tensorflow? error:No gradient defined for operation 'RandomShuffle'

There are three heterogeneous networks. 存在三个异构网络。 At the end of the processing, I need to reconstruct the final positive and negative samples in tensor. 在处理的最后,我需要重构张量中的最终正样本和负样本。 I need to shuffle them. 我需要洗牌。 I use the "tf.random_shuffle" method, error hint: No gradient defined for operation'Random Shuffle'. 我使用“ tf.random_shuffle”方法,错误提示:“ Random Shuffle”操作未定义渐变。 But I need gradients. 但是我需要渐变。 If I don't use the "tf.random_shuffle" method, I want to shuffle them artificially, how do I operate them? 如果不使用“ tf.random_shuffle”方法,则想人为地对其进行洗牌,该如何操作?

Now, I use the " tf.map_fn " method to simply alternate positive and negative combinations, one positive and one negative, and then one positive and one negative, and so on. 现在,我使用“ tf.map_fn”方法简单地交替使用正负组合,一个正负一,然后是一个正负一,依此类推。 But this is still a regular combination of samples, and how to shuffle the samples? 但这仍然是样本的常规组合,如何对样本进行混洗?

Here's a workaround: 解决方法:

tf.gather(batch, tf.random.shuffle(tf.range(tf.shape(batch)[0])))

[ https://github.com/tensorflow/tensorflow/issues/6269#issuecomment-465850464][1] [ https://github.com/tensorflow/tensorflow/issues/6269#issuecomment-465850464][1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM