preprocessor.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "ultra_infer/vision/common/processors/transform.h"
  16. #include "ultra_infer/vision/common/result.h"
  17. namespace ultra_infer {
  18. namespace vision {
  19. namespace classification {
  20. /*! @brief Preprocessor object for YOLOv5Cls serials model.
  21. */
  22. class ULTRAINFER_DECL YOLOv5ClsPreprocessor {
  23. public:
  24. /** \brief Create a preprocessor instance for YOLOv5Cls serials model
  25. */
  26. YOLOv5ClsPreprocessor();
  27. /** \brief Process the input image and prepare input tensors for runtime
  28. *
  29. * \param[in] images The input image data list, all the elements are returned
  30. * by cv::imread() \param[in] outputs The output tensors which will feed in
  31. * runtime \param[in] ims_info The shape info list, record input_shape and
  32. * output_shape \return true if the preprocess succeeded, otherwise false
  33. */
  34. bool Run(std::vector<FDMat> *images, std::vector<FDTensor> *outputs,
  35. std::vector<std::map<std::string, std::array<float, 2>>> *ims_info);
  36. /// Set target size, tuple of (width, height), default size = {224, 224}
  37. void SetSize(const std::vector<int> &size) { size_ = size; }
  38. /// Get target size, tuple of (width, height), default size = {224, 224}
  39. std::vector<int> GetSize() const { return size_; }
  40. protected:
  41. bool Preprocess(FDMat *mat, FDTensor *output,
  42. std::map<std::string, std::array<float, 2>> *im_info);
  43. // target size, tuple of (width, height), default size = {224, 224}
  44. std::vector<int> size_;
  45. };
  46. } // namespace classification
  47. } // namespace vision
  48. } // namespace ultra_infer