Python tensorflow.python.framework.graph_util_impl.convert_variables_to_constants() Examples
The following are 1
code examples of tensorflow.python.framework.graph_util_impl.convert_variables_to_constants().
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.framework.graph_util_impl
, or try the search function
.
Example #1
Source File: punctuator.py From keras-punctuator with MIT License | 4 votes |
def freeze(): checkpoint_prefix = os.path.join(TMP_DIR, "saved_checkpoint") checkpoint_state_name = "checkpoint_state" input_graph_name = "input_graph.pb" output_graph_name = "freezed.pb" saver_write_version = 1 # We'll create an input graph that has a single variable containing 1.0, # and that then multiplies it by 2. from tensorflow.python.framework import ops with ops.Graph().as_default(): from keras import backend as K K.set_learning_phase(0) model = createModel() model.load_weights(KERAS_WEIGHTS_FILE) sess = K.get_session() from tensorflow.python.framework.graph_util_impl import convert_variables_to_constants # convert_variables_to_constants(sess, sess.graph.as_graph_def(), [model.output.name.split(':')[0]]) testGraph(sess, '') from tensorflow.python.training import saver as saver_lib saver = saver_lib.Saver(write_version=saver_write_version) checkpoint_path = saver.save( sess, checkpoint_prefix, global_step=0, latest_filename=checkpoint_state_name) from tensorflow.python.framework import graph_io graph_io.write_graph(sess.graph, TMP_DIR, input_graph_name) sess.close() # We save out the graph to disk, and then call the const conversion # routine. input_graph_path = os.path.join(TMP_DIR, input_graph_name) input_saver_def_path = "" input_binary = False output_node_names = model.output.name.split(':')[0] restore_op_name = "save/restore_all" filename_tensor_name = "save/Const:0" output_graph_path = os.path.join(MODEL_DATA_DIR, output_graph_name) clear_devices = False from tensorflow.python.tools import freeze_graph freeze_graph.freeze_graph(input_graph_path, input_saver_def_path, input_binary, checkpoint_path, output_node_names, restore_op_name, filename_tensor_name, output_graph_path, clear_devices, "") exportWordIndex(loadWordIndex())