Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 341
Anny Avatar asked Apr 16 '19 05:04

Anny


1 Answers

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]

like image 139
Christopher Palm Avatar answered Nov 02 '22 07:11

Christopher Palm