【发布时间】:2021-09-29 11:12:43
【问题描述】:
我在 Jupyter 实验室中使用 Keras 来训练模型。
我希望能够手动停止训练并优雅地退出拟合。
现在我可以终止训练的唯一方法是通过 KeyboardInterrupt。
我如何使用 Keras 回调来优雅地终止训练——在某种程度上,我的 Keras 后代码也将在同一个单元格内执行——通过监听 KeyboardInterrupt 或接收来自小部件按钮的事件?
或者还有其他方法吗?
谢谢!
另见Does interrupting keras training in a Jupyter notebook save the training?
编辑:
我尝试过捕获KeyboardInterrupt(即Jupyter中停止按钮发送的SIGINT),如下:
try:
history=model.fit(...)
except KeyboardInterrupt:
pass
但现在我无法在上面的块之后访问history(用于绘图/持久化等)。我应该使用回调在每个(几个)时期编写模型并从文件中加载历史记录,还是有其他方法?
谢谢!
【问题讨论】:
标签: python keras jupyter jupyter-lab ipywidgets