我想將我的圖像數據從我的TFRecord
文件填充到tf.train.shuffle_batch()
。我有一個load_img_file()
函數,它讀取TFRecord
文件,進行預處理,並以[[圖像陣列,np.uint8
格式],[標籤數組,np.uint8
格式]]的格式返回圖像和單熱標籤。我做了這個操作tf.train.shuffle_batch()ValueError:無法推斷張量的等級:張量(「PyFunc:0」,dtype = uint8)
load_img_file_op = tf.py_func(self.load_img_file, [], [np.uint8, np.uint8])
它將該函數轉換爲操作。我已經驗證了該操作在做
data = tf.Session().run(load_img_file_op)
for n in range(50): #go through images
print data[1][n] #print one-hot label
self.image_set.display_img(data[0][n]) #display image
它成功地打印單熱標籤並顯示相應的圖像。
然而,當我嘗試做一些像
self.batch = tf.train.shuffle_batch(load_img_file_op, batch_size=self.batch_size, capacity=q_capacity, min_after_dequeue=10000)
我得到的錯誤
raise ValueError("Cannot infer Tensor's rank: %s" % tl[i]) ValueError: Cannot infer Tensor's rank: Tensor("PyFunc:0", dtype=uint8)"
我已經嘗試了許多變化,試圖以匹配的導向作用:
- 而不是
self.batch =
,我試過example_batch,label_batch =
(試圖獲得兩個值而不是一個)images
和labels
: - 有我
load_image_file()
功能和load_img_file_op
返回兩個不同的值設置enqueue_many
爲True - 。然後輸入他們像
tf.train.shuffle_batch([images, labels],...)
- 返回/在同一時間輸入只有一個圖像和標籤到
tf.train.shuffle_batch()
- 使用
tf.train.shuffle_batch_join()
似乎沒有任何工作,但我覺得我下面的guide的格式和我見過的各種其他教程。我究竟做錯了什麼?我很抱歉,如果我的錯誤是愚蠢的或微不足道的(搜索這個錯誤似乎沒有返回任何與我有關的東西)。感謝您的幫助和時間!
你可能想看看這個答案:https://stackoverflow.com/questions/42590431/output-from-tensorflow-py-func-has-unknown-rank-shape – npf