Apollo  6.0
Open source self driving car software
meta_statistics.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. 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  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 #pragma once
17 #include <memory>
18 #include <string>
19 #include <vector>
22 
23 namespace apollo {
24 namespace perception {
25 namespace benchmark {
26 
27 // similarity, precision, recall, confidence
28 struct SPRCTuple {
29  double similarity = 0.0;
30  double precision = 0.0;
31  double recall = 0.0;
32  double confidence = 0.0;
33 };
34 
36  void cal_orientation_similarity(const ObjectPtr& object,
37  const ObjectPtr& gt_object);
38  // if penalizes PI
39  static bool penalize_pi;
40  // direction angle difference
41  double delta = 0.0;
42  // orientation similarity
43  double similarity = 0.0;
44 };
45 
46 enum RangeType {
47  DISTANCE = 0,
48  VIEW = 1,
49  BOX = 2,
50  ROI = 3,
51 };
52 
53 void compute_ap_aos(
54  const std::vector<unsigned int>& cumulated_match_num_per_conf,
55  const std::vector<unsigned int>& cumulated_detection_num_per_conf,
56  const unsigned int total_gt_num, const unsigned int recall_dim, double* ap,
57  std::vector<SPRCTuple>* tuples,
58  const std::vector<double>& cumulated_orientation_similarity_per_conf =
59  std::vector<double>(),
60  double* aos = nullptr);
61 
63  public:
65  ~MetaStatistics() = default;
66  void reset();
67  // this operator designed for online update
68  MetaStatistics& operator+=(const MetaStatistics& rhs);
69  // get precision and recall for each range
70  void get_2017_detection_precision_and_recall(
71  std::vector<double>* precisions, std::vector<double>* recalls) const;
72  void get_2017_detection_visible_recall(std::vector<double>* recalls) const;
73  // get 2017 orientation aad
74  void get_2017_aad(std::vector<double>* aad) const;
75 
76  void get_2016_detection_precision_and_recall(
77  std::vector<double>* precisions, std::vector<double>* recalls) const;
78  // get ap, and pr-curve samples <precision, recall, confidence>
79  void get_2017_detection_ap_aos(double* ap, double* aos,
80  std::vector<SPRCTuple>* tuples) const;
81  void get_2017_detection_ap_per_type(
82  std::vector<double>* ap, std::vector<std::vector<SPRCTuple>>* tuples);
83  // get 2017 classification accuracy
84  void get_2017_classification_accuracy(
85  std::vector<std::vector<double>>* accuracys) const;
86  // get 2016 classification accuracy
87  // D1: type D2: range
88  void get_2016_classification_accuracy(
89  std::vector<std::vector<double>>* accuracys) const;
90  // get classification confusion matrix (normalized)
91  void get_classification_confusion_matrix(
92  std::vector<std::vector<double>>* matrix_gt_major,
93  std::vector<std::vector<double>>* matrix_det_major,
94  std::vector<std::vector<double>>* matrix_det_major_with_fp) const;
95 
96  friend std::ostream& operator<<(std::ostream& out, const MetaStatistics& rhs);
97  // class FrameStatistics will fill in the raw data
98  friend class FrameStatistics;
99 
100  public:
101  static void set_range_type(RangeType type);
102  static void set_recall_dim(unsigned int prc_dim);
103  static unsigned int get_type_index(const ObjectType& type);
104  static unsigned int get_range_index(const PositionMetric& position);
105  static unsigned int get_confidence_index(double confidence);
106  static unsigned int get_type_dim();
107  static unsigned int get_range_dim();
108  static unsigned int get_confidence_dim();
109  static std::string get_type(unsigned int index);
110  static std::string get_range(unsigned int index);
111  static double get_confidence(unsigned int index);
112  static unsigned int get_recall_dim();
113 
114  private:
115  static std::unique_ptr<BaseRangeInterface> _s_range_interface;
116  static unsigned int _s_recall_dim;
117  // record for detection precision and recall
118  // D1: range
119  std::vector<unsigned int> _total_detection_num;
120  std::vector<unsigned int> _total_groundtruth_num;
121  // match statisfy ji > TH criteria (17 KPI)
122  std::vector<unsigned int> _total_ji_match_num;
123  // visible groundtruth number and matches
124  std::vector<unsigned int> _total_visible_groundtruth_num;
125  std::vector<unsigned int> _total_visible_ji_match_num;
126  // angle difference sum in different range
127  std::vector<double> _total_yaw_angle_diff;
128  // match statisfy sum{N(o_i \cap o_gt)} / N(o_gt) > TH criteria (16 KPI)
129  // thus allow many to one match
130  std::vector<unsigned int> _total_hit_match_num;
131  std::vector<double> _total_ji_sum; // (16 KPI)
132  // record for detection ap
133  // D1: gt type D2: confidence (store #samples of confidence >= bin confidence)
134  std::vector<std::vector<unsigned int>> _cumulated_match_num_per_conf;
135  // D1: det type D2: confidence (store #samples of confidence >= bin
136  // confidence)
137  std::vector<std::vector<unsigned int>> _cumulated_det_alone_per_conf;
138  // record for detection aos
139  // D1: confidence (store #samples of confidence >= bin confidence)
140  std::vector<double> _cumulated_orientation_similarity_sum_per_conf;
141  // record for classification accuracy
142  // D1: range D2: groundtruth type D3: estimated type
143  std::vector<std::vector<std::vector<unsigned int>>> _confusion_matrix;
144  // record # of types of detections without groundtruth match
145  // D1: range D2: type
146  std::vector<std::vector<unsigned int>> _det_alone;
147  // record # of types of groundtruth without detection match
148  // D1: range D2: type
149  std::vector<std::vector<unsigned int>> _gt_alone;
150  // record # of under-segmented gt num
151  // D1: type
152  std::vector<unsigned int> _underseg_gt_num;
153 };
154 
155 } // namespace benchmark
156 } // namespace perception
157 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
ObjectType
Definition: object.h:31
Definition: meta_statistics.h:62
double precision
Definition: meta_statistics.h:30
static bool penalize_pi
Definition: meta_statistics.h:39
Definition: meta_statistics.h:28
double similarity
Definition: meta_statistics.h:29
std::shared_ptr< Object > ObjectPtr
Definition: object.h:158
Definition: meta_statistics.h:48
RangeType
Definition: meta_statistics.h:46
Definition: meta_statistics.h:50
double confidence
Definition: meta_statistics.h:32
std::ostream & operator<<(std::ostream &os, std::pair< A, B > &p)
Definition: util.h:158
Definition: meta_statistics.h:47
double recall
Definition: meta_statistics.h:31
Definition: meta_statistics.h:49
Definition: frame_statistics.h:36
void compute_ap_aos(const std::vector< unsigned int > &cumulated_match_num_per_conf, const std::vector< unsigned int > &cumulated_detection_num_per_conf, const unsigned int total_gt_num, const unsigned int recall_dim, double *ap, std::vector< SPRCTuple > *tuples, const std::vector< double > &cumulated_orientation_similarity_per_conf=std::vector< double >(), double *aos=nullptr)
Definition: position_metric.h:29