I'm new to keras and tensorflow. When I write programs with tensorflow, I must bulid a session to run the graph. However, when I use keras, although the backend is obviously tensorflow, I don't see session in the keras code. It seems all thing is done after the model.compile and model.fit.
So, how does Keras work? where is the tensorflow session? and instead of session, can I use eager execution with keras?
Thanks in advance and sorry for my English
TensorFlow Session is a session object which encapsulates the environment in which Operation objects are executed, and data objects are evaluated. TensorFlow requires a session to execute an operation and retrieve its calculated value. A session may own several resources, for example, tf. QueueBase, tf. Variable, tf.
Calling clear_session() releases the global state: this helps avoid clutter from old models and layers, especially when memory is limited.
It's not necessary to import all of the Keras and Tensorflow library functions. Instead, import just the function(s) you need for your project.
Keras doesn't directly have a session because it supports multiple backends. Assuming you use TF as backend, you can get the global session as:
from keras import backend as K
sess = K.get_session()
If, on the other hand, yo already have an open Session
and want to set it as the session Keras should use, you can do so via:
K.set_session(sess)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With