You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

stub_postprocess.cc 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "worker/postprocess.h"
  17. #include "mindspore_serving/ccsrc/common/tensor.h"
  18. namespace mindspore::serving {
  19. class StubCastFp32toInt32Postprocess : public PostprocessBase {
  20. public:
  21. Status Postprocess(const std::string &postprocess_name, const InstanceData &input, InstanceData *output) override {
  22. MSI_EXCEPTION_IF_NULL(output);
  23. auto x1 = input[0];
  24. if (x1->data_type() != kMSI_Float32) {
  25. return INFER_STATUS_LOG_ERROR(FAILED) << "Postprocess failed: Input data type invalid " << x1->data_type();
  26. }
  27. auto y1 = std::make_shared<Tensor>();
  28. y1->set_data_type(kMSI_Int32);
  29. y1->resize_data(x1->data_size());
  30. y1->set_shape(x1->shape());
  31. output->push_back(y1);
  32. auto x1_data = reinterpret_cast<const float *>(x1->data());
  33. auto y1_data = reinterpret_cast<int32_t *>(y1->mutable_data());
  34. for (size_t i = 0; i < y1->data_size() / 4; i++) {
  35. y1_data[i] = static_cast<int32_t>(x1_data[i]);
  36. }
  37. return SUCCESS;
  38. }
  39. size_t GetInputsCount(const std::string &postprocess_name) const override { return 1; }
  40. size_t GetOutputsCount(const std::string &postprocess_name) const override { return 1; }
  41. };
  42. REGISTER_POSTPROCESS(StubCastFp32toInt32Postprocess, "stub_postprocess_cast_fp32_to_int32_cpp")
  43. } // namespace mindspore::serving

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.