停止 Keras 调参器如果它找到了一个好的配置

huangapple go评论104阅读模式
英文:

Stop Keras Tuner if it has found a good configuration

问题

我知道我可以使用EarlyStopping或特殊回调来停止单个试验,如果准确度足够高,但是否有一种方法可以在这种情况下停止整个超参数调整?

  1. tuner = RandomSearch(
  2. hypermodel=model,
  3. objective=Objective(config.metric, direction=config.metric_direction),
  4. max_trials=config.max_trials,
  5. overwrite=False,
  6. directory=config.log_directory,
  7. project_name=config.project_name,
  8. )
  9. tuner.search(
  10. x=X_train,
  11. y=y_train,
  12. epochs=config.epochs,
  13. validation_data=data_test,
  14. callbacks=callbacks, # 这包括EarlyStopping和一个在达到一定准确度时终止的回调
  15. verbose=1,
  16. class_weight=class_weights,
  17. )
英文:

I know that I can stop single trials using EarlyStopping or special callbacks if the accuracy is high enough, but is there a way to stop the whole hyperparameter tuning in that case?

  1. tuner = RandomSearch(
  2. hypermodel=model,
  3. objective=Objective(config.metric, direction=config.metric_direction),
  4. max_trials=config.max_trials,
  5. overwrite=False,
  6. directory=config.log_directory,
  7. project_name=config.project_name,
  8. )
  9. tuner.search(
  10. x=X_train,
  11. y=y_train,
  12. epochs=config.epochs,
  13. validation_data=data_test,
  14. callbacks=callbacks, # This contains EarlyStopping and a callback that terminates when a certain acc has been reached
  15. verbose=1,
  16. class_weight=class_weights,
  17. )

答案1

得分: 0

好的,有一个解决方案:

如果您子类化了tuner类(例如RandomSearch),您可以在on_epoch_end中设置一个标志,当达到所需的准确性时。

然后,如果您重写search函数,您可以在标志被设置后立即中断while循环。

英文:

Okay, there is a solution:

If you subclass the tuner class (e.g. RandomSearch), you can set a flag in on_epoch_end when the desired accuracy is reached.

If you then overwrite the search function, you can interrupt the while loop as soon as the flag is set.

huangapple
  • 本文由 发表于 2023年6月16日 03:45:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定