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

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

Stop Keras Tuner if it has found a good configuration

问题

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

tuner = RandomSearch(
    hypermodel=model,
    objective=Objective(config.metric, direction=config.metric_direction),
    max_trials=config.max_trials,
    overwrite=False,
    directory=config.log_directory,
    project_name=config.project_name,
)

tuner.search(
    x=X_train,
    y=y_train,
    epochs=config.epochs,
    validation_data=data_test,
    callbacks=callbacks,  # 这包括EarlyStopping和一个在达到一定准确度时终止的回调
    verbose=1,
    class_weight=class_weights,
)
英文:

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?

        tuner = RandomSearch(
            hypermodel=model,
            objective=Objective(config.metric, direction=config.metric_direction),
            max_trials=config.max_trials,
            overwrite=False,
            directory=config.log_directory,
            project_name=config.project_name,
        )

        tuner.search(
            x=X_train,
            y=y_train,
            epochs=config.epochs,
            validation_data=data_test,
            callbacks=callbacks,  # This contains EarlyStopping and a callback that terminates when a certain acc has been reached
            verbose=1,
            class_weight=class_weights,
        )

答案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:

确定