英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论