TensorFlow Serving C++ API Documentation
regression_service.cc
1 /* Copyright 2017 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 #include "tensorflow_serving/servables/tensorflow/regression_service.h"
17 
18 #include "tensorflow/core/lib/core/errors.h"
19 #include "tensorflow/core/platform/tracing.h"
20 #include "tensorflow_serving/apis/regressor.h"
21 #include "tensorflow_serving/core/servable_handle.h"
22 #include "tensorflow_serving/servables/tensorflow/regressor.h"
23 #include "tensorflow_serving/servables/tensorflow/util.h"
24 
25 namespace tensorflow {
26 namespace serving {
27 
28 Status TensorflowRegressionServiceImpl::Regress(
29  const RunOptions& run_options, ServerCore* core,
30  const thread::ThreadPoolOptions& thread_pool_options,
31  const RegressionRequest& request, RegressionResponse* response) {
32  // Verify Request Metadata and create a ServableRequest
33  if (!request.has_model_spec()) {
34  return tensorflow::Status(
35  static_cast<absl::StatusCode>(absl::StatusCode::kInvalidArgument),
36  "Missing ModelSpec");
37  }
38 
39  return RegressWithModelSpec(run_options, core, thread_pool_options,
40  request.model_spec(), request, response);
41 }
42 
43 Status TensorflowRegressionServiceImpl::RegressWithModelSpec(
44  const RunOptions& run_options, ServerCore* core,
45  const thread::ThreadPoolOptions& thread_pool_options,
46  const ModelSpec& model_spec, const RegressionRequest& request,
47  RegressionResponse* response) {
48  TRACELITERAL("TensorflowRegressionServiceImpl::RegressWithModelSpec");
49 
50  ServableHandle<SavedModelBundle> saved_model_bundle;
51  TF_RETURN_IF_ERROR(core->GetServableHandle(model_spec, &saved_model_bundle));
52  return RunRegress(run_options, saved_model_bundle->meta_graph_def,
53  saved_model_bundle.id().version,
54  saved_model_bundle->session.get(), request, response,
55  thread_pool_options);
56 }
57 
58 } // namespace serving
59 } // namespace tensorflow