python - Tensorflow - 不同长度的喂食示例

标签 python 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]

知道如何解决这个问题吗?

最佳答案

来自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/

相关文章:

python - 在 Mac 中以管理员身份运行已编译的 python (py2app)

windows-installer - 在 Windows 上安装 Tensorflow 错误

python - python如何解释命令行参数?

关于阅读小文件的python风格问题

python - 使用 .apply、.applymap、.groupby 转换 Pandas DataFrame 中的异常值

tensorflow - tf.nn.dynamic_rnn tensorflow 函数的输出分析

python - Tensorflow:如何替换或修改渐变?

python - 启动 Tensorboard - NameError : name 'tensorboard' is not defined

python - 如何在 Keras、Tensorflow 中导入 LSTM

python - 更改多级字典值的更多 pythonic 方法