2017-04-04 58 views
0

因爲我是tensorflow的新手,我不知道如何定義tf.PaddingFIFOQueue的形狀來將元素設置爲N * 1數組。我認爲下面的代碼應該可以工作,但它會產生錯誤...我可以幫助我調試tf.PaddingFIFOQueue錯誤嗎?

你能給我一個提示來調試嗎?

import tensorflow as tf 
import numpy as np 

a = tf.placeholder(dtype= tf.float32, shape = [None, 1]) 
b = tf.placeholder(dtype= tf.float32, shape = [None, 1]) 

ab_value = np.random.randn(5,1) 
m = ab_value.reshape(-1, 1) 

q_ab = tf.PaddingFIFOQueue(32, ['float32', 'float32'], shapes = [[None, 1], [None, 1]]) 
q_ab_en = q_ab.enqueue_many([a, b]) 

sess = tf.Session() 
sess.run(q_ab_en, feed_dict = {a: ab_value, b: ab_value}) 

#a_dq, b_dq = q_ab.dequeue_many(1) 

File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\ops\data_flow_ops.py", line 375, in enqueue_many val.get_shape()[1:].assert_is_compatible_with(shape)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\framework\tensor_shape.py", line 756, in assert_is_compatible_with raise ValueError("Shapes %s and %s are incompatible" % (self, other)) ValueError: Shapes (1,) and (?,1) are incompatible

回答

0

是A和B單一元素或多個元素?

enqueue_many相當於分批排隊調用。所以如果你有a.shape = [5,1]調用enqueue_many(a)等價於調用enqueue(a [0]),enqueue(a [1]),...,enqueue(a [-1]) 。

如果這是您的預期行爲,您應該將隊列的形狀更改爲: q_ab = tf.PaddingFIFOQueue(32,['float32','float32'],shapes = [[1],[1]] )

如果a和b代表單個樣本,則應該使用enqueue而不是enqueue_many。

+0

謝謝你的回答!對我很有幫助!我只是通過使用enqueue而不是enqueue_many來解決問題。 – drw

相關問題