Apply standard TensorFlow optimizations to the graph_def. Args: graph_def: Frozen GraphDef to be optimized. input_arrays: List of arrays that are considered inputs of the graph. output_arrays: List of arrays that are considered outputs of the graph. config: tf.ConfigProto. gra
(graph_def,
input_arrays,
output_arrays,
config,
graph=None)
| 171 | |
| 172 | |
| 173 | def run_graph_optimizations(graph_def, |
| 174 | input_arrays, |
| 175 | output_arrays, |
| 176 | config, |
| 177 | graph=None): |
| 178 | """Apply standard TensorFlow optimizations to the graph_def. |
| 179 | |
| 180 | Args: |
| 181 | graph_def: Frozen GraphDef to be optimized. |
| 182 | input_arrays: List of arrays that are considered inputs of the graph. |
| 183 | output_arrays: List of arrays that are considered outputs of the graph. |
| 184 | config: tf.ConfigProto. |
| 185 | graph: TensorFlow Graph. Required when Eager mode is enabled. (default None) |
| 186 | |
| 187 | Returns: |
| 188 | A new, optimized GraphDef. |
| 189 | """ |
| 190 | meta_graph = _export_meta_graph(graph_def=graph_def, graph=graph) |
| 191 | |
| 192 | # We need to add a collection called 'train_op' so that grappler |
| 193 | # knows what the outputs are. |
| 194 | fetch_collection = _meta_graph_pb2.CollectionDef() |
| 195 | for array in input_arrays + output_arrays: |
| 196 | fetch_collection.node_list.value.append(array.name) |
| 197 | meta_graph.collection_def["train_op"].CopyFrom(fetch_collection) |
| 198 | |
| 199 | return tf_optimizer.OptimizeGraph(config, meta_graph) |
| 200 | |
| 201 | |
| 202 | def _convert_op_hints_if_present(sess, graph_def, output_tensors, |
no test coverage detected