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