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.

postprocess.h 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef MINDSPORE_SERVING_WORKER_POSTPROCESS_H
  17. #define MINDSPORE_SERVING_WORKER_POSTPROCESS_H
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <vector>
  21. #include <string>
  22. #include "common/serving_common.h"
  23. #include "common/instance.h"
  24. namespace mindspore::serving {
  25. class PostprocessBase : public std::enable_shared_from_this<PostprocessBase> {
  26. public:
  27. PostprocessBase() = default;
  28. virtual ~PostprocessBase() = default;
  29. virtual Status Postprocess(const std::string &postprocess_name, const InstanceData &input, InstanceData *output) = 0;
  30. virtual size_t GetInputsCount(const std::string &postprocess_name) const = 0;
  31. virtual size_t GetOutputsCount(const std::string &postprocess_name) const = 0;
  32. virtual bool IsPythonPostprocess() const { return false; }
  33. };
  34. class MS_API PostprocessStorage {
  35. public:
  36. void Register(const std::string &postprocess_name, std::shared_ptr<PostprocessBase> postprocess);
  37. std::shared_ptr<PostprocessBase> GetPostprocess(const std::string &postprocess_name) const;
  38. static PostprocessStorage &Instance();
  39. private:
  40. std::unordered_map<std::string, std::shared_ptr<PostprocessBase>> postprocess_map_;
  41. };
  42. class RegPostprocess {
  43. public:
  44. RegPostprocess(const std::string &postprocess_name, std::shared_ptr<PostprocessBase> postprocess);
  45. };
  46. #define REGISTER_POSTPROCESS(cls_name, postprocess_name) \
  47. static RegPostprocess g_register_postprocess_##cls_name(postprocess_name, std::make_shared<cls_name>());
  48. } // namespace mindspore::serving
  49. #endif // MINDSPORE_SERVING_WORKER_POSTPROCESS_H

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