如何清除使用Keras和Tensorflow(作为后端)创建的模型? [英] How can I clear a model created with Keras and Tensorflow(as backend)?
问题描述
在Jupyter Notebook中用Keras训练神经网络时遇到问题.我创建了具有几个隐藏层的顺序模型.训练模型并保存结果后,我想在同一会话中删除该模型并创建一个新模型,因为我有一个for
循环来检查不同参数的结果.但是据我了解到的错误,在更改参数,循环时,我只是在模型中添加了图层(即使我在循环中再次使用network = Sequential()
对其进行了初始化).所以我的问题是,如何才能完全清除以前的模型,或者如何在同一会话中初始化一个全新的模型?
I have a problem when training a neural net with Keras in Jupyter Notebook. I created a sequential model with several hidden layers. After training the model and saving the results, I want to delete this model and create a new model in the same session, as I have a for
loop that checks the results for different parameters. But as I understand the errors I get, when changing the parameters, when I loop over, I am just adding layers to the model (even though I initialise it again with network = Sequential()
inside the loop). So my question is, how can I completely clear the previous model or how can I initialise a completely new model in the same session?
推荐答案
keras.backend.clear_session()
应该清除以前的模型.来自 https://keras.io/backend/:
keras.backend.clear_session()
should clear the previous model. From https://keras.io/backend/:
销毁当前的TF图并创建一个新的TF图. 有助于避免旧模型/图层造成混乱.
Destroys the current TF graph and creates a new one. Useful to avoid clutter from old models / layers.
这篇关于如何清除使用Keras和Tensorflow(作为后端)创建的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!