tf.keras.backend.clear_session
Stay organized with collections
Save and categorize content based on your preferences.
Destroys the current TF graph and session, and creates a new one.
tf.keras.backend.clear_session()
Calling clear_session() releases the global graph state that Keras is
holding on to; resets the counters used for naming layers and
variables in Keras; and resets the learning phase. This helps avoid clutter
from old models and layers, especially when memory is limited, and a
common use-case for clear_session is releasing memory when building models
and layers in a loop.
import tensorflow as tf
layers = [tf.keras.layers.Dense(10) for _ in range(10)]
new_layer = tf.keras.layers.Dense(10)
print(new_layer.name)
dense_10
tf.keras.backend.set_learning_phase(1)
print(tf.keras.backend.learning_phase())
1
tf.keras.backend.clear_session()
new_layer = tf.keras.layers.Dense(10)
print(new_layer.name)
dense
print(tf.keras.backend.learning_phase())
0
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[]]