在tensorflow中實(shí)現(xiàn)去除不足一個(gè)batch的數(shù)據(jù)
更新時(shí)間:2020年01月20日 10:17:53 作者:Pywin
今天小編就為大家分享一篇在tensorflow中實(shí)現(xiàn)去除不足一個(gè)batch的數(shù)據(jù),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
我就廢話不多說了,直接上代碼吧!
#-*- 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有參數(shù),只能使用參數(shù)化迭代器
dataset = tf.data.Dataset.range(10)
# 定義參數(shù)化迭代器
dataset = dataset.shuffle(100)
dataset = dataset.apply(tf.contrib.data.batch_and_drop_remainder(3)) #每個(gè)batch3個(gè)數(shù)據(jù),不足3個(gè)舍棄
iterator = dataset.make_initializable_iterator()
next_element = iterator.get_next()
with tf.Session() as sess:
# 需要用參數(shù)初始化迭代器
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中實(shí)現(xiàn)去除不足一個(gè)batch的數(shù)據(jù)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
PyTorch如何創(chuàng)建自己的數(shù)據(jù)集
這篇文章主要介紹了PyTorch如何創(chuàng)建自己的數(shù)據(jù)集,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11
Python中低維數(shù)組填充高維數(shù)組的實(shí)現(xiàn)
今天小編就為大家分享一篇Python中低維數(shù)組填充高維數(shù)組的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12
pytorch機(jī)器學(xué)習(xí)softmax回歸的簡潔實(shí)現(xiàn)
這篇文章主要介紹了為大家介紹了pytorch機(jī)器學(xué)習(xí)中softmax回歸的簡潔實(shí)現(xiàn)方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-10-10
python2.7實(shí)現(xiàn)郵件發(fā)送功能
這篇文章主要為大家詳細(xì)介紹了python2.7實(shí)現(xiàn)郵件發(fā)送功能包,含文本、附件、正文圖片等,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12

