Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the tensorflow session in Keras

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

like image 231
LinTIna Avatar asked Dec 06 '18 14:12

LinTIna


People also ask

What is a TensorFlow session?

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.

What does clear session do in Keras?

Calling clear_session() releases the global state: this helps avoid clutter from old models and layers, especially when memory is limited.

Do I need to import TensorFlow to use Keras?

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.


1 Answers

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)
like image 183
GPhilo Avatar answered Oct 05 '22 21:10

GPhilo