您无需致电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() 返回所有搜索结果。
请参阅Tuner 类here 的文档。