简体   繁体   中英

What tf.keras.backend.clear_session actually do?

What is tf.keras.backend.clear_session actually do?

https://www.tensorflow.org/api_docs/python/tf/keras/backend/clear_session

How it's related to tf.reset_default_graph() and sess.close() ?

https://www.tensorflow.org/api_docs/python/tf/reset_default_graph

https://www.tensorflow.org/api_docs/python/tf/Session#close

There are two main concepts in TensorFlow 1.0 Graphs and Sessions .

  • Graph - It is a set of connected operations and placeholders which doesn't hold any tensor(numpy array) or values without a session. As an analogy, you can consider a food processing assembly line without any ingredients, but process and recipes are defined.

  • Session - It takes the graph and initializes the variable with initial values and ready to take some to feed in the placeholder to start implementing the operations defined the graph to the feed values in placeholders, at last, it will deliver you the final output from you desired operation node (in neural network nodes of the last layer.)(like feeding tomatoes and getting ketchup as output.)

    coming back to your real question.

  • If you use the tf.keras.backend.clear_session it will discard the values resides in the variable defined in the graph, leaving an empty vessel. (It will free up your RAM space.), now you can load weights from some other files.

  • If you use the tf.reset_default_graph() it will reset the graph and it will remove all the defined operations and their inter-connection with corresponding weights. Now you have to load both models architecture and weights for the execution.

practically it seems it is doing same stuff cause it is tf.reset_default_graph() will be called internally while calling k.clear_session() but clear_session will also intiate the fresh graph for the new operation you can check the source code here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM