2016-07-13 54 views
2

我的每个训练示例都是一个长度不同的列表。 我想找到一种方法将这些示例提供给图形。 以下是我通过创建一个列表,其元素是占位符未知尺寸的尝试。Tensorflow - 不同长度的喂养示例

graph2 = tf.Graph() 
with graph2.as_default(): 
    A = list() 
    for i in np.arange(3): 
     A.append(tf.placeholder(tf.float32 ,shape = [None,None])) 
    A_size = tf.shape(A) 

with tf.Session(graph=graph2) as session: 
    tf.initialize_all_variables().run() 
    feed_dict = {A[0]:np.zeros((3,7)) ,A[1] : np.zeros((3,2)) , A[2] : np.zeros((3,2)) } 
    print (type(feed_dict)) 
    B = session.run(A_size ,feed_dict=feed_dict) 
print type(B) 

不过,我得到了以下错误:

InvalidArgumentError: Shapes of all inputs must match: values[0].shape = [3,7] != values[1].shape = [3,2] 

如何解决它的任何想法?

回答

2

tf.placeholder文档:

shape: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape.

你需要写shape=None而不是shape=[None, None]。在您的代码中,Tensorflow不知道您正在处理可变大小的输入。

+0

它似乎没有工作,我仍然得到像以前一样的错误。 –

+0

哪条线给你错误? –