ppyolo_mbv3_large_coco.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2022 PaddlePaddle Authors. 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. #pragma once
  15. #include "core/general-server/general_model_service.pb.h"
  16. #include "core/general-server/op/general_infer_helper.h"
  17. #include "paddle_inference_api.h" // NOLINT
  18. #include <string>
  19. #include <vector>
  20. #include "opencv2/core.hpp"
  21. #include "opencv2/imgcodecs.hpp"
  22. #include "opencv2/imgproc.hpp"
  23. #include <chrono>
  24. #include <iomanip>
  25. #include <iostream>
  26. #include <ostream>
  27. #include <vector>
  28. #include <cstring>
  29. #include <fstream>
  30. #include <numeric>
  31. namespace baidu {
  32. namespace paddle_serving {
  33. namespace serving {
  34. class ppyolo_mbv3_large_coco
  35. : public baidu::paddle_serving::predictor::OpWithChannel<GeneralBlob> {
  36. public:
  37. typedef std::vector<paddle::PaddleTensor> TensorVector;
  38. DECLARE_OP(ppyolo_mbv3_large_coco);
  39. int inference();
  40. private:
  41. // preprocess
  42. std::vector<float> mean_ = {0.485f, 0.456f, 0.406f};
  43. std::vector<float> scale_ = {0.229f, 0.224f, 0.225f};
  44. bool is_scale_ = true;
  45. int im_shape_h = 320;
  46. int im_shape_w = 320;
  47. float scale_factor_h = 1.0f;
  48. float scale_factor_w = 1.0f;
  49. void preprocess_det(const cv::Mat &img, float *data, float &scale_factor_h,
  50. float &scale_factor_w, int im_shape_h, int im_shape_w,
  51. const std::vector<float> &mean,
  52. const std::vector<float> &scale, const bool is_scale);
  53. // read pics
  54. cv::Mat Base2Mat(std::string &base64_data);
  55. std::string base64Decode(const char *Data, int DataByte);
  56. };
  57. } // namespace serving
  58. } // namespace paddle_serving
  59. } // namespace baidu