23774

How can I clear a model created with Keras and Tensorflow(as backend)?

Question:

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?

Answer1:

keras.backend.clear_session() should clear the previous model. From <a href="https://keras.io/backend/" rel="nofollow">https://keras.io/backend/</a>:

<blockquote>

Destroys the current TF graph and creates a new one. Useful to avoid clutter from old models / layers.

</blockquote>

Recommend

  • asp.net json serializer adding backslash “\\” to my properties
  • How can I prevent page-break in CFDocument from occuring in middle of content?
  • Swift: How to get string values of days, months and year from a date picker?
  • Why doesn't if(cell == nil) work?
  • How can I upload files to firebase's cloud storage with a path using the admin sdk?
  • Fatal error: Call to a member function user() on boolean
  • R Multiple Regression Loop and Extract Coefficients
  • can I build CMakeLists.txt from a set of smaller files (to improve the readability and maintainabili
  • How to use CoreFoundation in QuickTime SDK for Windows?
  • Insert statement not working using execute(array()) of PDO Extension
  • Get last 15 lines from a large file in SFTP with phpseclib [duplicate]
  • Using django-multiupload within a ModelForm
  • async GET request with body from browser
  • integrity constraint violation: NOT NULL check constraint
  • How to modify the way a ForeignKey field is rendered in a Django admin page to avoid browser crash?
  • Reader monad - how does it conform to Monad interface?
  • Tkinter tkMessageBox disables Tkinter key bindings
  • How do I change the names of buttons on a message box?
  • In metro, get all inherited classes of an (abstract) class?
  • Bundling python(“.py”)files along with java class files for a web application
  • Signed Java web start application with Glassfish 4.1 and Java7
  • Unity Resources.load() won't work with external dll
  • C++11: Why rvalue reference parameter implicitly converted to lvalue
  • How to change the host IP sent in emails to new GitLab users to a publicly visible IP, not the local
  • Julia 1.0 UndefVarError - Scope of Variable
  • Add checkbox dynamically using angular 2
  • How to use array in autohotkey?
  • Stop an element moving with padding on hover
  • How to check if a database and tables exist in sql server in a vb .net project?
  • java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-ser
  • How to use Kaminari pagination gem with Sinatra and Mongoid?
  • Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?
  • How to include associated objects using gon in Rails/jQuery
  • How to call jQuery function in HTML returned by AJAX
  • Change cell value based on cell color in google spreadsheet
  • Stacked bar chart with continuous time-axis as x-axis
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • How to warp text around image in iOS?
  • Jersey serializes character value to ASCII equivalent numeric string
  • Firebase: How to read from external DB?