tensorflow dataset_ops shuffle()方法 (随机重新排列此数据集的元素)
生活随笔
收集整理的這篇文章主要介紹了
tensorflow dataset_ops shuffle()方法 (随机重新排列此数据集的元素)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 thenumber of elements from this dataset from which the newdataset will sample.tf.int64標量tf.Tensor,表示此數據集中要從中采樣新數據集的元素數。seed: (Optional.) A `tf.int64` scalar `tf.Tensor`, representing therandom 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 indicatesthat the dataset should be pseudorandomly reshuffled each time it isiterated 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 tftf.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'>
總結
以上是生活随笔為你收集整理的tensorflow dataset_ops shuffle()方法 (随机重新排列此数据集的元素)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tensorflow dataset_o
- 下一篇: tensorflow dataset_o