keras - CuDNN LSTM 超参数调整:Input_h 形状错误
问题描述
在为 LSTM 进行超参数调整时,我在大约 100-150 个时期后遇到了以下错误。
InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: Invalid input_h shape: [1,1,128] [1,32,128]
[[{{node cu_dnnlstm_1/CudnnRNN}}]]
(1) Invalid argument: Invalid input_h shape: [1,1,128] [1,32,128]
[[{{node cu_dnnlstm_1/CudnnRNN}}]]
[[loss/mul/_101]]
0 successful operations.
0 derived errors ignored.
在运行 CuDNNLSTM 以利用 GPU 而不是简单的 LSTM 时会出现此错误。我正在尝试在此模型上应用 GridSearchCV 以进行超参数调整。我不明白这个错误是什么意思,据我了解存在一些形状不匹配,但在这种情况下,模型不应该首先运行。
def create_model(neurons=(128,64),dropout_rate=0.2):
tf.reset_default_graph()
lstm_model = Sequential()
lstm_model.add(CuDNNLSTM(128, kernel_initializer='glorot_uniform', return_sequences=True, batch_input_shape=(1, 15, 7)))
lstm_model.add(Dropout(dropout_rate))
lstm_model.add(CuDNNLSTM(64, return_sequences=False))
lstm_model.add(Dense(look_forward))
opt = Nadam(lr=0.02)
lstm_model.compile(optimizer = opt, loss = 'mae',metrics=['mean_absolute_percentage_error'])
return lstm_model
# create and fit the LSTM network
model = KerasRegressor(build_fn=create_model, verbose=0)
# define the grid search parameters
dropout_rate = [0.2, 0.1, 0]
param_grid = dict(dropout_rate=dropout_rate)
grid = GridSearchCV(estimator=model, cv=3,param_grid=param_grid)
early_stopping = EarlyStopping(monitor='val_loss', patience=42)
lr_reducer = ReduceLROnPlateau(monitor='val_loss', factor=0.5,
patience=10, verbose=2, mode='auto', min_delta=0.0001, cooldown=0, min_lr=0)
grid_result = grid.fit(x_train, y_train, validation_data= (x_val, y_val),
callbacks=[early_stopping, lr_reducer], verbose=2, batch_size=1, epochs=5000)
它没有成功运行,而是给出了 InvalidArgumentError。我们希望模型能够成功运行每种超参数组合。
解决方案
推荐阅读
- android - Get Video and Audio buffer separately while recording video using front camera
- c# - return $"({x},{y})"; in c# Can you explain what is $ doing there?
- google-apps-script - Auto-fill custom function
- javascript - How i can change a class of a parent element
- tfs - TFS and VSTS - on premise and cloud source code
- php - How do I pass a python variable to a website via PHP
- azure - azure api manager terraform 查询
- python - Tkinter's root.mainloop() does not work in my application with a main loop
- python-3.x - 如何随机选择下一个代码段运行
- java - 多个线程,计算正在运行的线程数