TensorFlow Dataset

tensorflow dataset.shuffle dataset.batch dataset.repeat 理解 注意点

【Eager & Graph Execution】EagerTensor与Tensor,tf.function / tf.py_function / tf.numpy_function

https://tensorflow.google.cn/datasets/

Tensorflow Dataset API详解

tensorflow之dataset详解

import numpy as np
import tensorflow as tf
np.random.seed(0)
x = np.random.sample((11,2))
# make a dataset from a numpy array
print(x)

dataset = tf.data.Dataset.from_tensor_slices(x)
dataset = dataset.shuffle(2)  # 将数据打乱,数值越大,混乱程度越大
dataset = dataset.batch(4)  # 按照顺序取出4行数据,最后一次输出可能小于batch
dataset = dataset.repeat()  # 数据集重复了指定次数
# repeat()在batch操作输出完毕后再执行,若在之前,相当于先把整个数据集复制两次
#为了配合输出次数,一般默认repeat()空

# create the iterator
iter = dataset.make_one_shot_iterator()
el = iter.get_next()

with tf.Session() as sess:
    for i in range(6):
        value = sess.run(el)
        print(value)