Home | History | Annotate | Download | only in session_bundle
      1 /* Copyright 2016 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 // Shim for systems that need to load both SessionBundle and
     17 // SavedModelBundle interchangeably during migration to SavedModel.
     18 #ifndef TENSORFLOW_CONTRIB_SESSION_BUNDLE_BUNDLE_SHIM_H_
     19 #define TENSORFLOW_CONTRIB_SESSION_BUNDLE_BUNDLE_SHIM_H_
     20 
     21 #include <memory>
     22 
     23 #include "tensorflow/cc/saved_model/loader.h"
     24 #include "tensorflow/contrib/session_bundle/session_bundle.h"
     25 #include "tensorflow/core/lib/core/status.h"
     26 #include "tensorflow/core/lib/core/stringpiece.h"
     27 #include "tensorflow/core/protobuf/meta_graph.pb.h"
     28 #include "tensorflow/core/public/session.h"
     29 #include "tensorflow/core/public/session_options.h"
     30 
     31 namespace tensorflow {
     32 namespace serving {
     33 namespace internal {
     34 
     35 // Adds an entry (key and value) to the input map of the signature def. Builds
     36 // TensorInfos for the SignatureDefs by using the name and dtype information
     37 // from the supplied map.
     38 void AddInputToSignatureDef(
     39     const string& tensor_name,
     40     const std::unordered_map<string, DataType>& tensor_name_to_dtype,
     41     const string& input_map_key, SignatureDef* signature_def);
     42 
     43 // Adds an entry (key and value) to the output map of the signature def. Builds
     44 // TensorInfos for the SignatureDefs by using the name and dtype information
     45 // from the supplied map.
     46 void AddOutputToSignatureDef(
     47     const string& tensor_name,
     48     const std::unordered_map<string, DataType>& tensor_name_to_dtype,
     49     const string& output_map_key, SignatureDef* signature_def);
     50 
     51 // Converts signatures in the MetaGraphDef into a SignatureDefs in the
     52 // MetaGraphDef.
     53 Status ConvertSignaturesToSignatureDefs(MetaGraphDef* meta_graph_def);
     54 
     55 // Converts a SessionBundle to a SavedModelBundle.
     56 Status ConvertSessionBundleToSavedModelBundle(
     57     SessionBundle& session_bundle, SavedModelBundle* saved_model_bundle);
     58 
     59 }  // namespace internal
     60 
     61 // Loads a SavedModel from either a session-bundle path or a SavedModel bundle
     62 // path.
     63 Status LoadSessionBundleOrSavedModelBundle(
     64     const SessionOptions& session_options, const RunOptions& run_options,
     65     const string& export_dir, const std::unordered_set<string>& tags,
     66     SavedModelBundle* bundle);
     67 
     68 }  // namespace serving
     69 }  // namespace tensorflow
     70 #endif  // TENSORFLOW_CONTRIB_SESSION_BUNDLE_BUNDLE_SHIM_H_
     71