classification_runner.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*************************************************************************
  2. * Copyright (C) [2020] by Cambricon, Inc. All rights reserved
  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. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #ifndef EDK_SAMPLES_CLASSIFICATION_RUNNER_H_
  21. #define EDK_SAMPLES_CLASSIFICATION_RUNNER_H_
  22. #include <memory>
  23. #include <string>
  24. #include "cnosd.h"
  25. #include "cnpostproc.h"
  26. #include "device/mlu_context.h"
  27. #include "easybang/resize_and_colorcvt.h"
  28. #include "easyinfer/easy_infer.h"
  29. #include "easyinfer/mlu_memory_op.h"
  30. #include "easyinfer/model_loader.h"
  31. #include "runner.h"
  32. class ClassificationRunner : public StreamRunner {
  33. public:
  34. ClassificationRunner(const std::string& model_path, const std::string& func_name, const std::string& label_path,
  35. const std::string& data_path, bool show, bool save_video);
  36. ~ClassificationRunner();
  37. void Process(edk::CnFrame frame) override;
  38. private:
  39. edk::MluMemoryOp mem_op_;
  40. edk::EasyInfer infer_;
  41. edk::MluResizeConvertOp rc_op_;
  42. CnOsd osd_;
  43. std::shared_ptr<edk::ModelLoader> model_{nullptr};
  44. std::unique_ptr<edk::CnPostproc> postproc_{nullptr};
  45. std::unique_ptr<cv::VideoWriter> video_writer_{nullptr};
  46. void **mlu_output_{nullptr}, **cpu_output_{nullptr}, **mlu_input_{nullptr};
  47. bool show_;
  48. bool save_video_;
  49. };
  50. #endif // EDK_SAMPLES_CLASSIFICATION_RUNNER_H_