results.h 2.3 KB
Newer Older
C
Channingss 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
//   Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <iostream>
#include <string>
#include <vector>

namespace PaddleX {

J
jack 已提交
23 24 25 26
/*
 * @brief
 * This class represents mask in instance segmentation tasks.
 * */
C
Channingss 已提交
27 28
template <class T>
struct Mask {
J
jack 已提交
29
  // raw data of mask
C
Channingss 已提交
30
  std::vector<T> data;
J
jack 已提交
31
  // the shape of mask
C
Channingss 已提交
32 33 34 35 36 37 38
  std::vector<int> shape;
  void clear() {
    data.clear();
    shape.clear();
  }
};

J
jack 已提交
39
/*
S
syyxsxx 已提交
40
 * @brief
J
jack 已提交
41 42
 * This class represents target box in detection or instance segmentation tasks.
 * */
C
Channingss 已提交
43 44
struct Box {
  int category_id;
J
jack 已提交
45
  // category label this box belongs to
C
Channingss 已提交
46
  std::string category;
J
jack 已提交
47
  // confidence score
C
Channingss 已提交
48 49
  float score;
  std::vector<float> coordinate;
S
syyxsxx 已提交
50
  Mask<float> mask;
C
Channingss 已提交
51 52
};

J
jack 已提交
53 54 55 56
/*
 * @brief
 * This class is prediction result based class.
 * */
C
Channingss 已提交
57 58
class BaseResult {
 public:
J
jack 已提交
59
  // model type
C
Channingss 已提交
60 61 62
  std::string type = "base";
};

J
jack 已提交
63 64 65 66
/*
 * @brief
 * This class represent classification result.
 * */
C
Channingss 已提交
67 68 69 70 71 72 73 74
class ClsResult : public BaseResult {
 public:
  int category_id;
  std::string category;
  float score;
  std::string type = "cls";
};

J
jack 已提交
75 76 77 78
/*
 * @brief
 * This class represent detection or instance segmentation result.
 * */
C
Channingss 已提交
79 80
class DetResult : public BaseResult {
 public:
J
jack 已提交
81
  // target boxes
C
Channingss 已提交
82 83 84 85 86 87
  std::vector<Box> boxes;
  int mask_resolution;
  std::string type = "det";
  void clear() { boxes.clear(); }
};

J
jack 已提交
88 89 90 91
/*
 * @brief
 * This class represent segmentation result.
 * */
C
Channingss 已提交
92 93
class SegResult : public BaseResult {
 public:
J
jack 已提交
94
  // represent label of each pixel on image matrix
C
Channingss 已提交
95
  Mask<int64_t> label_map;
J
jack 已提交
96
  // represent score of each pixel on image matrix
C
Channingss 已提交
97
  Mask<float> score_map;
C
fix doc  
Channingss 已提交
98
  std::string type = "seg";
C
Channingss 已提交
99 100 101 102 103
  void clear() {
    label_map.clear();
    score_map.clear();
  }
};
C
fix doc  
Channingss 已提交
104
}  // namespace PaddleX