CuDNN LSTM超参数调整:Input_h形状错误

时间:2019-07-09 12:11:45

标签: keras deep-learning gpu grid-search

为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。我们希望模型能够针对每种超参数组合成功运行。

0 个答案:

没有答案