本文整理汇总了Python中tensorflow.python.keras.backend.get_session方法的典型用法代码示例。如果您正苦于以下问题:Python backend.get_session方法的具体用法?Python backend.get_session怎么用?Python backend.get_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.keras.backend
的用法示例。
在下文中一共展示了backend.get_session方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_model_to_tensorflow
# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_session [as 别名]
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")
示例2: _init_session
# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_session [as 别名]
def _init_session():
from tensorflow.python.keras import backend
sess = backend.get_session()
tf.get_default_graph()
set_session(sess)
return sess
示例3: on_train_begin
# 需要导入模块: from tensorflow.python.keras import backend [as 别名]
# 或者: from tensorflow.python.keras.backend import get_session [as 别名]
def on_train_begin(self, logs=None):
K.get_session().run(tf.tables_initializer())