Randomly shuffles the elements of this dataset. This dataset fills a buffer with `buffer_size` elements, then randomly samples elements from this buffer, replacing the selected elements with new elements. For perfect shuffling, a buffer size greater than or equal to the full size of
(self, buffer_size, seed=None, reshuffle_each_iteration=None)
| 945 | return Dataset.zip((Dataset.range(start, max_value), self)) |
| 946 | |
| 947 | def shuffle(self, buffer_size, seed=None, reshuffle_each_iteration=None): |
| 948 | """Randomly shuffles the elements of this dataset. |
| 949 | |
| 950 | This dataset fills a buffer with `buffer_size` elements, then randomly |
| 951 | samples elements from this buffer, replacing the selected elements with new |
| 952 | elements. For perfect shuffling, a buffer size greater than or equal to the |
| 953 | full size of the dataset is required. |
| 954 | |
| 955 | For instance, if your dataset contains 10,000 elements but `buffer_size` is |
| 956 | set to 1,000, then `shuffle` will initially select a random element from |
| 957 | only the first 1,000 elements in the buffer. Once an element is selected, |
| 958 | its space in the buffer is replaced by the next (i.e. 1,001-st) element, |
| 959 | maintaining the 1,000 element buffer. |
| 960 | |
| 961 | Args: |
| 962 | buffer_size: A `tf.int64` scalar `tf.Tensor`, representing the number of |
| 963 | elements from this dataset from which the new dataset will sample. |
| 964 | seed: (Optional.) A `tf.int64` scalar `tf.Tensor`, representing the random |
| 965 | seed that will be used to create the distribution. See |
| 966 | `tf.compat.v1.set_random_seed` for behavior. |
| 967 | reshuffle_each_iteration: (Optional.) A boolean, which if true indicates |
| 968 | that the dataset should be pseudorandomly reshuffled each time it is |
| 969 | iterated over. (Defaults to `True`.) |
| 970 | |
| 971 | Returns: |
| 972 | Dataset: A `Dataset`. |
| 973 | """ |
| 974 | return ShuffleDataset(self, buffer_size, seed, reshuffle_each_iteration) |
| 975 | |
| 976 | def cache(self, filename=""): |
| 977 | """Caches the elements in this dataset. |