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 // Helpers for working with the SignatureDefs of TensorFlow SavedModels. 17 18 #ifndef TENSORFLOW_CONTRIB_SAVED_MODEL_CC_SAVED_MODEL_SIGNATURE_DEF_UTILS_H_ 19 #define TENSORFLOW_CONTRIB_SAVED_MODEL_CC_SAVED_MODEL_SIGNATURE_DEF_UTILS_H_ 20 21 #include <string> 22 #include <utility> 23 #include <vector> 24 25 #include "tensorflow/core/framework/tensor.h" 26 #include "tensorflow/core/lib/core/status.h" 27 #include "tensorflow/core/protobuf/meta_graph.pb.h" 28 29 namespace tensorflow { 30 31 // Finds the entry in meta_graph_def.signature_def with the given key, or 32 // returns NotFound and leaves *signature_def unchanged. NOTE: The output 33 // SignatureDef* points into meta_graph_def and may be invalidated by changes 34 // to that protocol buffer, as usual. 35 Status FindSignatureDefByKey(const MetaGraphDef& meta_graph_def, 36 const string& signature_def_key, 37 const SignatureDef** signature_def); 38 39 // Finds the entry in signature_def.inputs with the given key, or returns 40 // NotFound and leaves *tensor_info unchanged. NOTE: The output TensorInfo* 41 // points into signature_def and may be invalidated by changes to that protocol 42 // buffer, as usual. 43 Status FindInputTensorInfoByKey(const SignatureDef& signature_def, 44 const string& tensor_info_key, 45 const TensorInfo** tensor_info); 46 47 // Finds the entry in signature_def.outputs with the given key, or returns 48 // NotFound and leaves *tensor_info unchanged. NOTE: The output TensorInfo* 49 // points into signature_def and may be invalidated by changes to that protocol 50 // buffer, as usual. 51 Status FindOutputTensorInfoByKey(const SignatureDef& signature_def, 52 const string& tensor_info_key, 53 const TensorInfo** tensor_info); 54 55 // Finds the entry in signature_def.inputs with the given key and copies out 56 // the name of this Tensor in the graph, or returns NotFound and leaves *name 57 // unchanged. 58 Status FindInputTensorNameByKey(const SignatureDef& signature_def, 59 const string& tensor_info_key, string* name); 60 61 // Finds the entry in signature_def.outputs with the given key and copies out 62 // the name of this Tensor in the graph, or returns NotFound and leaves *name 63 // unchanged. 64 Status FindOutputTensorNameByKey(const SignatureDef& signature_def, 65 const string& tensor_info_key, string* name); 66 67 // Determine whether a SignatureDef can be served by TensorFlow Serving. 68 bool IsValidSignature(const SignatureDef& signature_def); 69 70 } // namespace tensorflow 71 72 #endif // TENSORFLOW_CONTRIB_SAVED_MODEL_CC_SAVED_MODEL_SIGNATURE_DEF_UTILS_H_ 73