我的每个训练示例都是一个不同长度的列表。 我正在尝试找到一种方法将这些示例输入到图表中。 下面是我尝试通过创建一个列表来实现此目的,该列表的元素是尺寸未知的占位符。
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]
知道如何解决这个问题吗?
最佳答案
来自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 不知道您正在处理可变大小的输入。
关于python - Tensorflow - 不同长度的喂食示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38346983/