我就废话不多说了,直接上代码吧!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#-*- coding:utf-8 -*- import tensorflow as tf import numpy as np value1 = tf.placeholder(dtype = tf.float32) value2 = tf.placeholder(dtype = tf.float32) value3 = value1 + value2 #定义的dataset有参数,只能使用参数化迭代器 dataset = tf.data.Dataset. range ( 10 ) # 定义参数化迭代器 dataset = dataset.shuffle( 100 ) dataset = dataset. apply (tf.contrib.data.batch_and_drop_remainder( 3 )) #每个batch3个数据,不足3个舍弃 iterator = dataset.make_initializable_iterator() next_element = iterator.get_next() with tf.Session() as sess: # 需要用参数初始化迭代器 for i in range ( 2 ): sess.run(iterator.initializer) while True : try : value = sess.run(next_element) result = sess.run(value3,feed_dict = {value1:value,value2:value}) print (result) except tf.errors.OutOfRangeError: print ( "End of epoch %d" % i) break |
以上这篇在tensorflow中实现去除不足一个batch的数据就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_36076233/article/details/81063127