results.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (c) 2020 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 <iostream>
  16. #include <string>
  17. #include <vector>
  18. namespace PaddleX {
  19. /*
  20. * @brief
  21. * This class represents mask in instance segmentation tasks.
  22. * */
  23. template <class T>
  24. struct Mask {
  25. // raw data of mask
  26. std::vector<T> data;
  27. // the shape of mask
  28. std::vector<int> shape;
  29. void clear() {
  30. data.clear();
  31. shape.clear();
  32. }
  33. };
  34. /*
  35. * @brief
  36. * This class represents target box in detection or instance segmentation tasks.
  37. * */
  38. struct Box {
  39. int category_id;
  40. // category label this box belongs to
  41. std::string category;
  42. // confidence score
  43. float score;
  44. std::vector<float> coordinate;
  45. Mask<int> mask;
  46. };
  47. /*
  48. * @brief
  49. * This class is prediction result based class.
  50. * */
  51. class BaseResult {
  52. public:
  53. // model type
  54. std::string type = "base";
  55. };
  56. /*
  57. * @brief
  58. * This class represent classification result.
  59. * */
  60. class ClsResult : public BaseResult {
  61. public:
  62. int category_id;
  63. std::string category;
  64. float score;
  65. std::string type = "cls";
  66. };
  67. /*
  68. * @brief
  69. * This class represent detection or instance segmentation result.
  70. * */
  71. class DetResult : public BaseResult {
  72. public:
  73. // target boxes
  74. std::vector<Box> boxes;
  75. int mask_resolution;
  76. std::string type = "det";
  77. void clear() { boxes.clear(); }
  78. };
  79. /*
  80. * @brief
  81. * This class represent segmentation result.
  82. * */
  83. class SegResult : public BaseResult {
  84. public:
  85. // represent label of each pixel on image matrix
  86. Mask<int64_t> label_map;
  87. // represent score of each pixel on image matrix
  88. Mask<float> score_map;
  89. std::string type = "seg";
  90. void clear() {
  91. label_map.clear();
  92. score_map.clear();
  93. }
  94. };
  95. } // namespace PaddleX