dataset中shuffle()、repeat()、batch()用法

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)

 

 

更多的不同和进阶可以参考这个博客

 https://blog.csdn.net/qq_16234613/article/details/81703228

posted @ 2020-01-20 20:49  星涅爱别离  阅读(4163)  评论(0编辑  收藏  举报