簡體   English   中英

使用Tensorflow批處理非圖像數據集

[英]Batching for a non-image data set with Tensorflow

我是tensorflow的初學者。 我有一個包含43個輸入和一個輸出的數據集。 我將創建一個數據迷你批次以運行深度學習。

這是我的輸入:

x = tf.placeholder(tf.float32, shape=[None, 43])
y_ = tf.placeholder(tf.float32, shape=[None])

我從matlab文件中獲取它們,看起來:

train_mat = train_mat["binary_train"].value
feed_dict={x:Train[0:100,0:43] , y_:Train[0:100,43]}

我要進行隨機批處理,而不是調用0:100記錄。 我看見

tf.train.batch

但是,我不知道它是如何工作的。 你能指導我怎么做嗎。

謝謝,阿夫申

tf.train.batch和其他類似方法基於tf.train.batch ,最適合並行並行異步加載大量樣本。 此處的文檔介紹了在TensorFlow中使用隊列的基本知識。 還有另一個博客描述了如何從文件中讀取數據

如果要使用隊列,則不需要placeholderfeed_dict

對於您的特定情況,潛在的解決方案可能如下所示:

from tensorflow.python.training import queue_runner

# capacity and min_after_dequeue could be set according to your case
q = tf.RandomShuffleQueue(1000, 500, tf.float32)
enq = q.enqueue_many(train_mat)
queue_runner.add_queue_runner(queue_runner.QueueRunner(q, [enq]))

deq = q.dequeue()
input = deq[:, 0:43]
label = deq[:, 43]

x, y_ = tf.train.batch([input, label], 100)

# then you can use x and y_ directly in inference and train process.

上面的代碼基於某些假設,因為所提供的信息不足。 但是,我希望代碼能以某種方式激發您的靈感。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM