【问题标题】:Python - Cannot feed value of shape (64, 25, 9) for Tensor 'Placeholder:0', which has shape '(?, 25, 25)'Python - 无法为具有形状“(?,25,25)”的张量“占位符:0”提供形状(64、25、9)的值
【发布时间】:2018-08-06 10:40:20
【问题描述】:

我正在尝试在 python 3.5 中训练我的 RNN-LSTM 模型,这是我的代码,我的数据集是一个 3D 加速度计数据集

X = tf.placeholder(tf.float32, [None, config.n_steps, config.n_inputs])
Y = tf.placeholder(tf.float32, [None, config.n_classes])

with tf.Session() as sess:
    tf.global_variables_initializer().run()

    for epoch in range(training_epochs):
        cost_history = np.empty(shape=[0],dtype=float)
        for b in range(total_batches):
            offset = (b * config.batch_size) % (train_y.shape[0] - config.batch_size)
            batch_x = train_x[offset:(offset + config.batch_size), :, :]
            batch_y = train_y[offset:(offset + config.batch_size), :]

            print ("batch_x shape =",batch_x.shape)
            print ("batch_y shape =",batch_y.shape)

            _, c = sess.run([optimizer, cost],feed_dict={X: batch_x, Y : batch_y})
            cost_history = np.append(cost_history,c)
        loss_over_time[epoch] = np.mean(cost_history)

但它给了我以下错误

Traceback (most recent call last):
  File "C:\Users\hp\Downloads\Deep-Learning-for-Human-Activity-Recognition-master\ModelCreation\RNN\FFLSTM\fflstm.py", line 250, in <module>
    _, c = sess.run([optimizer, cost],feed_dict={X: batch_x, Y : batch_y})
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 895, in run
    run_metadata_ptr)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1100, in _run
    % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (64, 25, 9) for Tensor 'Placeholder:0', which has shape '(?, 25, 25)'

这是我的数据集的形状

n_inputs len(X_train[0][0]) 25
batch_x shape = (64, 25, 9)
batch_y shape = (64, 2)
X <tf.Tensor 'Placeholder:0' shape=(?, 25, 25) dtype=float32>
Y <tf.Tensor 'Placeholder_1:0' shape=(?, 2) dtype=float32>

【问题讨论】:

    标签: python-3.x tensorflow signal-processing placeholder


    【解决方案1】:

    batch_x 的形状 (64, 25, 9) 与模型预期的 (?, 25, 25) 不匹配。

    您应该将 batch_x 的形状更改为 (64, 25, 25),或者将 X 占位符更改为 (?, 25, 9)

    【讨论】:

    • 如何修改X占位符?
    • config.n_inputs 设置为 9,使其变为 [None, config.n_steps, 9]。基本上批处理形状必须匹配输入X 形状。
    • @HadeerEl-Zayat 这能解决您的问题吗?
    • 很遗憾没有:(
    • 我尝试将 batch_x 形状更改为 (64,25,25) 但它不起作用
    猜你喜欢
    • 2018-06-06
    • 2018-08-04
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    • 2022-08-12
    • 1970-01-01
    相关资源
    最近更新 更多