在 Keras Tuner 运行 期间如何保存进度?
How do you save progress during a Keras Tuner run?
我目前正在使用 Keras Tuner 在免费的 Google Colab 实例上进行更大的搜索 space。由于使用限制,我的搜索 运行 将在完成之前中断。我想定期保存我的搜索进度以防这些中断,并在 Colab 资源再次对我可用时从最后一个检查点恢复。
我找到了有关如何从 运行 保存特定模型的文档,但我想保存整个搜索状态,包括已经尝试过的内容和这些实验的结果。
我可以只调用 Tuner.get_state()
,保存结果,然后从 Tuner.set_state()
中断的地方继续吗?或者有别的办法吗?
您不需要调用 tuner.get_state()
和 tuner.set_state()
。在实例化 Tuner
时,说 RandomSearch
,如 example、
中所述
# While creating the tuner for the first time
tuner = RandomSearch(
build_model,
objective="val_accuracy",
max_trials=3,
executions_per_trial=2,
directory="my_dir",
project_name="helloworld",
)
您需要设置参数 directory
和 project_name
。检查点保存在这个目录中。您可以将此目录保存为 ZIP 文件并使用 files.download()
.
下载
当您获得一个新的 Colab 实例时,解压缩该存档并恢复 my_dir
目录。使用
再次实例化 Tuner
# While loading the Tuner
tuner = RandomSearch(
build_model,
objective="val_accuracy",
max_trials=3,
executions_per_trial=2,
directory="my_dir", # <----- Use the directory as you did earlier
overwrite=False, # <-------
project_name="helloworld",
)
现在开始搜索,您会发现 best params so far
没有改变。此外,tuner.results_summary()
returns 所有搜索结果。
请参阅 Tuner
class here 的文档。
我目前正在使用 Keras Tuner 在免费的 Google Colab 实例上进行更大的搜索 space。由于使用限制,我的搜索 运行 将在完成之前中断。我想定期保存我的搜索进度以防这些中断,并在 Colab 资源再次对我可用时从最后一个检查点恢复。 我找到了有关如何从 运行 保存特定模型的文档,但我想保存整个搜索状态,包括已经尝试过的内容和这些实验的结果。
我可以只调用 Tuner.get_state()
,保存结果,然后从 Tuner.set_state()
中断的地方继续吗?或者有别的办法吗?
您不需要调用 tuner.get_state()
和 tuner.set_state()
。在实例化 Tuner
时,说 RandomSearch
,如 example、
# While creating the tuner for the first time
tuner = RandomSearch(
build_model,
objective="val_accuracy",
max_trials=3,
executions_per_trial=2,
directory="my_dir",
project_name="helloworld",
)
您需要设置参数 directory
和 project_name
。检查点保存在这个目录中。您可以将此目录保存为 ZIP 文件并使用 files.download()
.
当您获得一个新的 Colab 实例时,解压缩该存档并恢复 my_dir
目录。使用
Tuner
# While loading the Tuner
tuner = RandomSearch(
build_model,
objective="val_accuracy",
max_trials=3,
executions_per_trial=2,
directory="my_dir", # <----- Use the directory as you did earlier
overwrite=False, # <-------
project_name="helloworld",
)
现在开始搜索,您会发现 best params so far
没有改变。此外,tuner.results_summary()
returns 所有搜索结果。
请参阅 Tuner
class here 的文档。