• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #include "tensorflow/core/common_runtime/graph_constructor.h"
16 #include "tensorflow/core/graph/node_builder.h"
17 #include "tensorflow/tools/graph_transforms/transform_utils.h"
18 
19 namespace tensorflow {
20 namespace graph_transforms {
21 
22 // Remove control dependencies in preparation for inference.
23 // In the tensorflow graph, control dependencies are represented as extra
24 // inputs which are referenced with "^tensor_name".
25 // See node_def.proto for more details.
RemoveControlDependencies(const GraphDef & input_graph_def,const TransformFuncContext & context,GraphDef * output_graph_def)26 Status RemoveControlDependencies(const GraphDef& input_graph_def,
27                 const TransformFuncContext& context,
28                 GraphDef* output_graph_def) {
29     output_graph_def->Clear();
30     for (const NodeDef& node : input_graph_def.node()) {
31         NodeDef* new_node = output_graph_def->mutable_node()->Add();
32         *new_node = node;
33         new_node->clear_input();
34         for (const auto& input : node.input()) {
35             if (input[0] != '^') {
36                 new_node->add_input(input);
37             }
38         }
39     }
40     return OkStatus();
41 }
42 
43 REGISTER_GRAPH_TRANSFORM("remove_control_dependencies", RemoveControlDependencies);
44 
45 }  // namespace graph_transforms
46 }  // namespace tensorflow
47