如何修复TensorFlow中的值错误?

2024-09-23 04:20:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我用TensorFlow尝试了一些东西,但出现了以下错误:

ValueError: Input 0 of layer gru is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 3)

我怎样才能修好它


Tags: ofthelayerinputistensorflow错误with
1条回答
网友
1楼 · 发布于 2024-09-23 04:20:08

我可以用示例代码重现您的问题tf.keras.layers.GRU需要输入一个三维张量,形状为[batch, timesteps, feature]

复制代码

import tensorflow as tf
inputs = tf.random.normal([32, 8])
gru = tf.keras.layers.GRU(4)
output = gru(inputs)
print(output.shape)

输出

ValueError: Input 0 of layer gru_1 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (32, 8)

工作样本代码

import tensorflow as tf
inputs = tf.random.normal([32, 10, 8])
gru = tf.keras.layers.GRU(4)
output = gru(inputs)
print(output.shape)

输出

(32, 4)

相关问题 更多 >