TensorFlow Serving C++ API Documentation
saved_model_bundle_source_adapter.h
1 /* Copyright 2016 Google Inc. 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 #ifndef TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_SOURCE_ADAPTER_H_
17 #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_SOURCE_ADAPTER_H_
18 
19 #include "tensorflow/cc/saved_model/loader.h"
20 #include "tensorflow/core/lib/core/status.h"
21 #include "tensorflow/core/platform/macros.h"
22 #include "tensorflow_serving/core/loader.h"
23 #include "tensorflow_serving/core/simple_loader.h"
24 #include "tensorflow_serving/core/source_adapter.h"
25 #include "tensorflow_serving/core/storage_path.h"
26 #include "tensorflow_serving/servables/tensorflow/saved_model_bundle_factory.h"
27 #include "tensorflow_serving/servables/tensorflow/saved_model_bundle_source_adapter.pb.h"
28 
29 namespace tensorflow {
30 namespace serving {
31 
32 // A SourceAdapter that creates SavedModelBundle Loaders from SavedModel paths.
33 // It keeps a SavedModelBundleFactory as its state, which may house a batch
34 // scheduler that is shared across all of the SavedModel bundles it emits.
36  : public UnarySourceAdapter<StoragePath, std::unique_ptr<Loader>> {
37  public:
38  static Status Create(const SavedModelBundleSourceAdapterConfig& config,
39  std::unique_ptr<SavedModelBundleSourceAdapter>* adapter);
40 
42 
43  private:
45 
47  std::unique_ptr<SavedModelBundleFactory> bundle_factory);
48 
49  SimpleLoader<SavedModelBundle>::CreatorVariant GetServableCreator(
50  std::shared_ptr<SavedModelBundleFactory> bundle_factory,
51  const StoragePath& path) const;
52 
53  Status Convert(const StoragePath& path,
54  std::unique_ptr<Loader>* loader) override;
55 
56  // We use a shared ptr to share ownership with Loaders we emit, in case they
57  // outlive this object.
58  std::shared_ptr<SavedModelBundleFactory> bundle_factory_;
59 
60  TF_DISALLOW_COPY_AND_ASSIGN(SavedModelBundleSourceAdapter);
61 };
62 
63 } // namespace serving
64 } // namespace tensorflow
65 
66 #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_SOURCE_ADAPTER_H_