简体   繁体   English

ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 60, 5),找到的形状 =(None, 60, 7)

[英]ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 60, 5), found shape=(None, 60, 7)

regressor.add(LSTM(units = 60, activation = 'relu', return_sequences = True, input_shape = (X_train.shape[1], 5)))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 70, activation = 'relu', return_sequences = True, input_shape = (X_train.shape[1], 5)))
regressor.add(Dropout(0.2))
regressor.add(LSTM(units = 90, activation = 'relu', return_sequences = True, input_shape = (X_train.shape[1], 5)))
regressor.add(Dropout(0.2))

regressor.add(LSTM(units = 140, activation = 'relu', return_sequences = True, input_shape = (X_train.shape[1], 5)))
regressor.add(Dropout(0.2))

regressor.add(Dense(units =1))
regressor.summary()


regressor.compile(optimizer = 'adam', loss='mean_absolute_error')
regressor.fit(X_train, Y_train, epochs = 20, batch_size =50)[enter image description here][1]

On running this code;在运行这段代码时; the value error raised while I was preparing my model for prediction.在我准备 model 进行预测时出现的值错误。 Help me to rectify it帮我改正

Epoch 1/20
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-535f5f5c29a7> in <module>()
----> 1 regressor.fit(X_train, Y_train, epochs = 20, batch_size =50)

1 frames
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
    65     except Exception as e:  # pylint: disable=broad-except
    66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
    68     finally:
    69       del filtered_tb

/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs)
  1145           except Exception as e:  # pylint:disable=broad-except
  1146             if hasattr(e, "ag_error_metadata"):
-> 1147               raise e.ag_error_metadata.to_exception(e)
  1148             else:
  1149               raise

ValueError: in user code:

   File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1021, in train_function  *
       return step_function(self, iterator)
   File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1010, in step_function  **
       outputs = model.distribute_strategy.run(run_step, args=(data,))
   File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1000, in run_step  **
       outputs = model.train_step(data)
   File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 859, in train_step
       y_pred = self(x, training=True)
   File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler
       raise e.with_traceback(filtered_tb) from None
   File "/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py", line 264, in assert_input_compatibility
       raise ValueError(f'Input {input_index} of layer "{layer_name}" is '

   ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 60, 5), found shape=(None, 60, 7)

On running the code;在运行代码时; I came across this error on my python interpretor.我在 python 解释器上遇到了这个错误。 Let me know the correct compatibility!让我知道正确的兼容性!

The error pretty much says it all.错误几乎说明了一切。 The first LSTM layer in your model expects a batch of time series, each having 60 timesteps and 5 features per timestep, but somehow you fed it a batch of time series each having 60 steps and 7 features. model 中的第一个 LSTM 层需要一批时间序列,每个时间序列有 60 个时间步,每个时间步有5 个特征,但不知何故,你给它提供了一批时间序列,每个时间序列有 60 个步骤和7 个特征。 You might check your X_train.shape[2] to see if it is 7.您可以检查X_train.shape[2]看它是否为 7。

Also, the way you're using the output of LSTM layers is incorrect.此外,您使用 output LSTM 层的方式不正确。 You might want to go through this answer andofficial tensorflow documentation to see what are the outputs of a LSTM layer with return_sequences set to True .您可能希望 go 通过此答案官方 tensorflow 文档来查看return_sequences设置为True的 LSTM 层的输出是什么。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError: 层“sequential_1”的输入 0 与层不兼容:预期形状=(None, 60, 1),发现形状=(None, 59, 1) - ValueError: Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 60, 1), found shape=(None, 59, 1) 层“sequential_3”的输入0与层不兼容:预期形状=(无,60),找到形状=(5,174) - Input 0 of layer "sequential_3" is incompatible with the layer: expected shape=(None, 60), found shape=(5, 174) ValueError:“顺序”层的输入 0 与层不兼容:预期形状 =(无,223461,5),找到形状 =(无,5) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 223461, 5), found shape=(None, 5) ValueError:层“顺序”的输入0与层不兼容:预期形状=(无,90),发现形状=(无,2,90) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 90), found shape=(None, 2, 90) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 455, 30),找到的形状 =(None, 30) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 455, 30), found shape=(None, 30) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(无,33714,12),找到形状 =(无,12) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 33714, 12), found shape=(None, 12) | ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 28, 28),找到的形状 =(None, 28, 3) - | ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 28, 28), found shape=(None, 28, 3) ValueError: 层“sequential_32”的输入 0 与层不兼容:预期形状=(None, 3, 1),发现形状=(32, 0, 1) - ValueError: Input 0 of layer "sequential_32" is incompatible with the layer: expected shape=(None, 3, 1), found shape=(32, 0, 1) Keras LSTM ValueError:层“顺序”的输入 0 与层不兼容:预期形状 =(无,478405,33),找到形状 =(1、33) - Keras LSTM ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 478405, 33), found shape=(1, 33) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状=(无,128,128,3),找到形状=(32,128,3) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 128, 128, 3), found shape=(32, 128, 3)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM