国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

TensorFlow數(shù)據(jù)輸入的方法示例

2020-02-15 21:54:53
字體:
供稿:網(wǎng)友

讀取數(shù)據(jù)(Reading data)

TensorFlow輸入數(shù)據(jù)的方式有四種:

    tf.data API:可以很容易的構(gòu)建一個復(fù)雜的輸入通道(pipeline)(首選數(shù)據(jù)輸入方式)(Eager模式必須使用該API來構(gòu)建輸入通道) Feeding:使用Python代碼提供數(shù)據(jù),然后將數(shù)據(jù)feeding到計算圖中。 QueueRunner:基于隊列的輸入通道(在計算圖計算前從隊列中讀取數(shù)據(jù)) Preloaded data:用一個constant常量將數(shù)據(jù)集加載到計算圖中(主要用于小數(shù)據(jù)集)

1. tf.data API

關(guān)于tf.data.Dataset的更詳盡解釋請看《programmer's guide》。tf.data API能夠從不同的輸入或文件格式中讀取、預(yù)處理數(shù)據(jù),并且對數(shù)據(jù)應(yīng)用一些變換(例如,batching、shuffling、mapping function over the dataset),tf.data API 是舊的 feeding、QueueRunner的升級。

2. Feeding

注意:Feeding是數(shù)據(jù)輸入效率最低的方式,應(yīng)該只用于小數(shù)據(jù)集和調(diào)試(debugging)

TensorFlow的Feeding機制允許我們將數(shù)據(jù)輸入計算圖中的任何一個Tensor。因此可以用Python來處理數(shù)據(jù),然后直接將處理好的數(shù)據(jù)feed到計算圖中 。

run()eval()中用feed_dict來將數(shù)據(jù)輸入計算圖:

with tf.Session(): input = tf.placeholder(tf.float32) classifier = ... print(classifier.eval(feed_dict={input: my_python_preprocessing_fn()}))

雖然你可以用feed data替換任何Tensor的值(包括variables和constants),但最好的使用方法是使用一個tf.placeholder節(jié)點(專門用于feed數(shù)據(jù))。它不用初始化,也不包含數(shù)據(jù)。一個placeholder沒有被feed數(shù)據(jù),則會報錯。

使用placeholder和feed_dict的一個實例(數(shù)據(jù)集使用的是MNIST)見tensorflow/examples/tutorials/mnist/fully_connected_feed.py

3. QueueRunner

注意:這一部分介紹了基于隊列(Queue)API構(gòu)建輸入通道(pipelines),這一方法完全可以使用 tf.data API來替代。

一個基于queue的從文件中讀取records的通道(pipline)一般有以下幾個步驟:

    文件名列表(The list of filenames) 文件名打亂(可選)(Optional filename shuffling) epoch限制(可選)(Optional epoch limit) 文件名隊列(Filename queue) 與文件格式匹配的Reader(A Reader for the file format) decoder(A decoder for a record read by the reader) 預(yù)處理(可選)(Optional preprocessing) Example隊列(Example queue)

3.1 Filenames, shuffling, and epoch limits

對于文件名列表,有很多方法:1. 使用一個constant string Tensor(比如:["file0", "file1"])或者 [("file%d" %i) for i in range(2)];2. 使用 tf.train.match_filenames_once 函數(shù);3. 使用 tf.gfile.Glob(path_pattern)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 黔西县| 吉木萨尔县| 江源县| 澄城县| 炉霍县| 囊谦县| 邵东县| 孟村| 中江县| 定西市| 杭锦旗| 蓝山县| 兴城市| 宁国市| 阳曲县| 安康市| 龙井市| 合阳县| 黄浦区| 扎鲁特旗| 清镇市| 尼玛县| 广丰县| 图片| 赣州市| 县级市| 兰州市| 宁化县| 德兴市| 牡丹江市| 黑山县| 永州市| 遵义县| 漾濞| 原阳县| 毕节市| 南乐县| 汉川市| 收藏| 芒康县| 四川省|