[英]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.