Reputation: 2777
There's an argument in that function seed=something. Even when I set its value, the shuffle give random results. I want the same results.
tf.random.suffle(tf.range(5), seed=5)
Upvotes: 2
Views: 1939
Reputation: 400
Came across this question. It seems like there is now a tf.random.experimental.stateless_shuffle
that should give reproducible results.
To get random seeds, you can use tf.random.Generator
.
Upvotes: 0
Reputation: 12607
If you want to reproduce shuffle results, use (on TF 2.0 beta) the following
tf.random.set_seed(5)
tf.random.shuffle(tf.range(5))
<tf.Tensor: id=35, shape=(5,), dtype=int32, numpy=array([0, 4, 1, 3, 2], dtype=int32)>
tf.random.set_seed(5)
tf.random.shuffle(tf.range(5))
<tf.Tensor: id=41, shape=(5,), dtype=int32, numpy=array([0, 4, 1, 3, 2], dtype=int32)>
tf.random.set_seed(5)
tf.random.shuffle(tf.range(5))
<tf.Tensor: id=47, shape=(5,), dtype=int32, numpy=array([0, 4, 1, 3, 2], dtype=int32)>
About the seed you have used, it indeed fails to reproduce results, tested in TF 2.0 beta
In TF 1.x I believe the right functions is tf.random.set_random_seed
From the docs, I can see there are op level seed, and graph level seed. You are setting the op level, which is not enough - setting the graph level seed with the function in the code above solves this behavior.
Upvotes: 3