Home | History | Annotate | Download | only in graph
      1 /* Copyright 2015 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/graph/validate.h"
     17 
     18 #include "tensorflow/core/framework/graph_def_util.h"
     19 #include "tensorflow/core/framework/node_def.pb.h"
     20 #include "tensorflow/core/framework/node_def_util.h"
     21 #include "tensorflow/core/framework/op_def_util.h"
     22 #include "tensorflow/core/framework/versions.pb.h"
     23 #include "tensorflow/core/lib/core/errors.h"
     24 #include "tensorflow/core/platform/types.h"
     25 
     26 namespace tensorflow {
     27 namespace graph {
     28 
     29 Status ValidateGraphDef(const GraphDef& graph_def,
     30                         const OpRegistryInterface& op_registry) {
     31   Status s;
     32   const int version = graph_def.versions().producer();
     33   for (const NodeDef& node_def : graph_def.node()) {
     34     // Look up the OpDef for the node_def's op name.
     35     const OpDef* op_def;
     36     TF_RETURN_IF_ERROR(op_registry.LookUpOpDef(node_def.op(), &op_def));
     37     TF_RETURN_IF_ERROR(ValidateNodeDef(node_def, *op_def));
     38     TF_RETURN_IF_ERROR(CheckOpDeprecation(*op_def, version));
     39   }
     40 
     41   return s;
     42 }
     43 
     44 Status ValidateGraphDefAgainstOpRegistry(
     45     const GraphDef& graph_def, const OpRegistryInterface& op_registry) {
     46   GraphDef copy(graph_def);
     47   TF_RETURN_IF_ERROR(AddDefaultAttrsToGraphDef(&copy, op_registry, 0));
     48   return ValidateGraphDef(copy, op_registry);
     49 }
     50 
     51 Status ValidateGraphDefAgainstOpList(const GraphDef& graph_def,
     52                                      const OpList& op_list) {
     53   OpListOpRegistry registry(&op_list);
     54   return ValidateGraphDefAgainstOpRegistry(graph_def, registry);
     55 }
     56 
     57 void GetOpListForValidation(OpList* op_list, const OpRegistry& op_registry) {
     58   op_registry.Export(false, op_list);
     59   RemoveDescriptionsFromOpList(op_list);
     60 }
     61 
     62 }  // namespace graph
     63 }  // namespace tensorflow
     64