Anny
Anny

Reputation: 61

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'. 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?

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. But this is still a regular combination of samples, and how to shuffle the samples?

Upvotes: 6

Views: 1546

Answers (1)

Christopher Palm
Christopher Palm

Reputation: 71

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]

Upvotes: 5

Related Questions