Tensorflow.js tf.data.Dataset class .shuffle() Method
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.data.Dataset.shuffle() method randomly shuffles a tensor along its first dimension.
tf.data.Dataset.shuffle( buffer_size, seed=None, reshuffle_each_iteration=None )
- buffer_size: This is the number of elements from which the new dataset will be sampled.
- seed[optional]: It is an optional parameter used to create a random seed for the distribution, to see the same results use same seed.
- reshuffle_each_iteration: A Boolean, which is true indicates that the dataset should be pseudo randomly reshuffled each time it is iterated over. Default value is true. It is Optional parameter.
Return Value: A tensor with same shape and data type as value, but shuffled along its first dimension.
Example 1: In this example first we will create a tensor and then shuffle it, In this example reshuffle_each_iteration is True
3 4 1 2 5 6 3 4 2 5 6 1
Example 2: In this example, seed is set to an Integer, whenever a specific integer is used it will generate that specific output
2 1 3 2 1 3