Python tensorflow.python.keras.backend.get_session() Examples

The following are 4 code examples of tensorflow.python.keras.backend.get_session(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow.python.keras.backend , or try the search function .
Example #1
Source Project: ImageAI   Author: OlafenwaMoses   File: __init__.py    License: MIT License 5 votes vote down vote up
def save_model_to_tensorflow(self, new_model_folder, new_model_name=""):

        """
        'save_model_to_tensorflow' function allows you to save your loaded Keras (.h5) model and save it to the Tensorflow (.pb) model format.
        - new_model_folder (required), the path to the folder you want the converted Tensorflow model to be saved
        - new_model_name (required), the desired filename for your converted Tensorflow model e.g 'my_new_model.pb'

        :param new_model_folder:
        :param new_model_name:
        :return:
        """

        if(self.__modelLoaded == True):
            out_prefix = "output_"
            output_dir = new_model_folder
            if os.path.exists(output_dir) == False:
                os.mkdir(output_dir)
            model_name = os.path.join(output_dir, new_model_name)

            keras_model = self.__model_collection[0]


            out_nodes = []

            for i in range(len(keras_model.outputs)):
                out_nodes.append(out_prefix + str(i + 1))
                tf.identity(keras_model.output[i], out_prefix + str(i + 1))

            sess = K.get_session()

            from tensorflow.python.framework import graph_util, graph_io

            init_graph = sess.graph.as_graph_def()

            main_graph = graph_util.convert_variables_to_constants(sess, init_graph, out_nodes)

            graph_io.write_graph(main_graph, output_dir, name=model_name, as_text=False)
            print("Tensorflow Model Saved") 
Example #2
Source Project: FATE   Author: FederatedAI   File: dense_model.py    License: Apache License 2.0 5 votes vote down vote up
def _init_session():
    from tensorflow.python.keras import backend
    sess = backend.get_session()
    tf.get_default_graph()
    set_session(sess)
    return sess 
Example #3
Source Project: FATE   Author: FederatedAI   File: nn_model.py    License: Apache License 2.0 5 votes vote down vote up
def _init_session():
    from tensorflow.python.keras import backend
    sess = backend.get_session()
    tf.get_default_graph()
    set_session(sess)
    return sess 
Example #4
Source Project: camera-trap-classifier   Author: marco-willi   File: hooks.py    License: MIT License 5 votes vote down vote up
def on_train_begin(self, logs=None):
        K.get_session().run(tf.tables_initializer())