MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / freeze_graph

Function freeze_graph

tensorflow/lite/python/util.py:214–251  ·  view source on GitHub ↗

Returns a frozen GraphDef. Runs a Grappler pass and freezes a graph with Variables in it. Otherwise the existing GraphDef is returned. The Grappler pass is only run on models that are frozen in order to inline the functions in the graph. If OpHints is present, it will try to convert the OpH

(sess, input_tensors, output_tensors)

Source from the content-addressed store, hash-verified

212
213
214def freeze_graph(sess, input_tensors, output_tensors):
215 """Returns a frozen GraphDef.
216
217 Runs a Grappler pass and freezes a graph with Variables in it. Otherwise the
218 existing GraphDef is returned. The Grappler pass is only run on models that
219 are frozen in order to inline the functions in the graph.
220 If OpHints is present, it will try to convert the OpHint graph.
221
222 Args:
223 sess: TensorFlow Session.
224 input_tensors: List of input tensors.
225 output_tensors: List of output tensors (only .name is used from this).
226
227 Returns:
228 Frozen GraphDef.
229 """
230 # Runs a Grappler pass in order to inline any functions in the graph.
231 # Asides from inlining any simple function, Grappler will also try to lower
232 # while loop into switch merge representation which is undesired for Ophints,
233 # so we simply remove those attributes to prevent Grappler from doing so.
234 graph_def = _convert_to_constants.disable_lower_using_switch_merge(
235 sess.graph_def)
236 config = get_grappler_config(["function"])
237 graph_def = run_graph_optimizations(
238 graph_def, input_tensors, output_tensors, config, graph=sess.graph)
239
240 # If ophints are present, just convert them.
241 hinted_outputs_nodes = find_all_hinted_output_nodes(sess)
242 if hinted_outputs_nodes:
243 return _convert_op_hints_if_present(sess, graph_def, output_tensors,
244 hinted_outputs_nodes)
245
246 if not is_frozen_graph(sess):
247 output_arrays = [get_tensor_name(tensor) for tensor in output_tensors]
248 return tf_graph_util.convert_variables_to_constants(sess, graph_def,
249 output_arrays)
250 else:
251 return sess.graph_def
252
253
254def is_frozen_graph(sess):

Callers

nothing calls this directly

Calls 6

get_grappler_configFunction · 0.85
run_graph_optimizationsFunction · 0.85
is_frozen_graphFunction · 0.85
get_tensor_nameFunction · 0.85

Tested by

no test coverage detected