小编Hey*_*ate的帖子

ValueError:lstm_1 层的输入 0 与该层不兼容:预期 ndim=3,发现 ndim=2。收到完整形状:(无,64)

我一直很难理解这个错误消息的含义。我看过很多帖子,比如

Keras LSTM 层的 4D 输入

ValueError: 层顺序的输入 0 与层不兼容: : 预期 min_ndim=4, 发现 ndim=3

ValueError:输入 0 与层 lstm_13 不兼容:预期 ndim=3,发现 ndim=4

层顺序的输入0与期望ndim=3的层不兼容,发现ndim=2。收到完整形状:[无,1]

预期 ndim=3,发现 ndim=2

但他们似乎都没有解决我的问题。

我有

batch_train_dataset = tf.data.Dataset.from_tensor_slices((train_features, train_labels)).shuffle(512).batch(batch_size)

for i,x in enumerate(batch_train_dataset):
  print("x[0].ndim: ", x[0].ndim)
  print("x[0].shape: ", x[0].shape)
  print("x[1].shape: ", x[1].shape)
  if i==0:
    break
##########OUTPUT###########
x[0].ndim:  3
x[0].shape:  (64, 32, 1000)
x[1].shape:  (64,)
Run Code Online (Sandbox Code Playgroud)

我的个人数据具有一个形状,(64,32,1000)其中64是batch_size,32是时间步长,1000是许多特征。

这是我的模型。

num_classes = len(index_to_label)

lstm_model = tf.keras.Sequential([
    tf.keras.layers.Masking(mask_value=0.0), # DO NOT REMOVE THIS LAYER …
Run Code Online (Sandbox Code Playgroud)

python lstm keras tensorflow

1
推荐指数
1
解决办法
4394
查看次数

标签 统计

keras ×1

lstm ×1

python ×1

tensorflow ×1