我用TensorFlow尝试了一些东西,得到了这个错误:
ValueError: Input 0 of layer gru is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 3)
如何解决这个问题?
我可以用示例代码重现您的问题。tf.keras.layers.GRU
期望输入A三维张量,形状为[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)