1 | /* Copyright 2017 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 | |
16 | #include "tensorflow/core/framework/function.h" |
17 | #include "tensorflow/core/framework/graph_def_util.h" |
18 | #include "tensorflow/tools/graph_transforms/transform_utils.h" |
19 | |
20 | namespace tensorflow { |
21 | namespace graph_transforms { |
22 | |
23 | // Sets any parameters not specified in a node to their defaults. |
24 | Status AddDefaultAttributes(const GraphDef& input_graph_def, |
25 | const TransformFuncContext& context, |
26 | GraphDef* output_graph_def) { |
27 | // Find all of the ops that are currently defined. |
28 | std::unique_ptr<FunctionLibraryDefinition> flib_def( |
29 | new FunctionLibraryDefinition(OpRegistry::Global(), |
30 | input_graph_def.library())); |
31 | // Works in-place, so copy over the original graph. |
32 | *output_graph_def = input_graph_def; |
33 | TF_RETURN_IF_ERROR(AddDefaultAttrsToGraphDef(output_graph_def, *flib_def, 0)); |
34 | return OkStatus(); |
35 | } |
36 | |
37 | REGISTER_GRAPH_TRANSFORM("add_default_attributes" , AddDefaultAttributes); |
38 | |
39 | } // namespace graph_transforms |
40 | } // namespace tensorflow |
41 | |