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