我有一个 keras LSTM 模型(回归器):
def model_builder(hp):
model = Sequential()
hp_units = hp.Int('units', min_value=32, max_value=512, step=32)
model.add(LSTM(units=hp_units, input_shape=(trainX.shape[1], trainX.shape[2])))
model.add(Dropout(0.2))
model.add(Dense(1))
hp_learning_rate = hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])
model.compile(loss='mean_squared_error', optimizer='adam')
return model
我按如下方式设置调谐器:
tuner = kt.Hyperband(model_builder,
objective='val_mean_squared_error',
max_epochs=10,
factor=3)
跑步时
tuner.search(X_train, y_train, epochs=50, validation_split=0.2, callbacks=[stop_early])
我收到此错误:
Search: Running Trial #3
Value |Best Value So Far |Hyperparameter
64 |352 |units
0.0001 |0.01 |learning_rate
2 |2 |tuner/epochs
0 |0 |tuner/initial_epoch
2 |2 |tuner/bracket
0 |0 |tuner/round
Epoch 1/2
104/104 ━━━━━━━━━━━━━━━━━━━━ 6s 29ms/step - loss: 0.0641 - val_loss: 0.0042
Epoch 2/2
104/104 ━━━━━━━━━━━━━━━━━━━━ 2s 24ms/step - loss: 0.0074 - val_loss: 0.0043
Traceback (most recent call last):
File "/home/tillys/python/usr/local/lib/python3.10/site-packages/keras_tuner/src/engine/base_tuner.py", line 274, in _try_run_and_update_trial
self._run_and_update_trial(trial, *fit_args, **fit_kwargs)
File "/home/tillys/python/usr/local/lib/python3.10/site-packages/keras_tuner/src/engine/base_tuner.py", line 265, in _run_and_update_trial
tuner_utils.convert_to_metrics_dict(
File "/home/tillys/python/usr/local/lib/python3.10/site-packages/keras_tuner/src/engine/tuner_utils.py", line 132, in convert_to_metrics_dict
[convert_to_metrics_dict(elem, objective) for elem in results]
File "/home/tillys/python/usr/local/lib/python3.10/site-packages/keras_tuner/src/engine/tuner_utils.py", line 132, in <listcomp>
[convert_to_metrics_dict(elem, objective) for elem in results]
File "/home/tillys/python/usr/local/lib/python3.10/site-packages/keras_tuner/src/engine/tuner_utils.py", line 145, in convert_to_metrics_dict
best_value, _ = _get_best_value_and_best_epoch_from_history(
File "/home/tillys/python/usr/local/lib/python3.10/site-packages/keras_tuner/src/engine/tuner_utils.py", line 116, in _get_best_value_and_best_epoch_from_history
objective_value = objective.get_value(metrics)
File "/home/tillys/python/usr/local/lib/python3.10/site-packages/keras_tuner/src/engine/objective.py", line 59, in get_value
return logs[self.name]
KeyError: 'val_mean_squared_error'
该模型在没有 keras hyperband 的情况下运行良好。 我对这个 KeyError 有点困惑:
'val_mean_squared_error'
任何想法将不胜感激。