def shuffle(self, buffer_size, seed=None, reshuffle_each_iteration=None):
"""Randomly shuffles the elements of this dataset.
随机重新排列此数据集的元素。
Args:
buffer_size: A `tf.int64` scalar `tf.Tensor`, representing the
number of elements from this dataset from which the new
dataset will sample.
tf.int64标量tf.Tensor,表示此数据集中要从中采样新数据集的元素数。
seed: (Optional.) A `tf.int64` scalar `tf.Tensor`, representing the
random seed that will be used to create the distribution. See
`tf.set_random_seed` for behavior.
tf.int64标量tf.Tensor,表示将用于创建分布的随机种子。
有关行为,请参见“ tf.set_random_seed”。
reshuffle_each_iteration: (Optional.) A boolean, which if true indicates
that the dataset should be pseudorandomly reshuffled each time it is
iterated over. (Defaults to `True`.)
布尔值,如果为true,则表示每次迭代数据集时都应伪随机地重排。 (默认为“ True”。)
Returns:
Dataset: A `Dataset`. 数据集:一个“数据集”。
"""
return ShuffleDataset(self, buffer_size, seed, reshuffle_each_iteration)
# -*- coding: utf-8 -*-
"""
@File : 191208_test_Eager_execution_once_cls.py
@Time : 2019/12/8 12:25
@Author : Dontla
@Email : sxana@qq.com
@Software: PyCharm
"""
import tensorflow as tf
tf.enable_eager_execution()
ds_tensors = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4, 5, 6])
print(type(ds_tensors)) # <class 'tensorflow.python.data.ops.dataset_ops.TensorSliceDataset'>
print(type(ds_tensors.map(tf.square))) # <class 'tensorflow.python.data.ops.dataset_ops.MapDataset'>
print(type(ds_tensors.map(tf.square).shuffle(2))) # <class 'tensorflow.python.data.ops.dataset_ops.ShuffleDataset'>
print(type(
ds_tensors.map(tf.square).shuffle(2).batch(2))) # <class 'tensorflow.python.data.ops.dataset_ops.BatchDataset'>
来源:CSDN
作者:Dontla
链接:https://blog.csdn.net/Dontla/article/details/103486351