Skip to content

Commit 7081a61

Browse files
authored
feat(perception_online_evaluator): publish metrics of each object class (#6556)
Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent e1a3139 commit 7081a61

File tree

6 files changed

+163
-74
lines changed

6 files changed

+163
-74
lines changed

evaluator/perception_online_evaluator/include/perception_online_evaluator/metrics_calculator.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "perception_online_evaluator/metrics/metric.hpp"
2020
#include "perception_online_evaluator/parameters.hpp"
2121
#include "perception_online_evaluator/stat.hpp"
22+
#include "perception_online_evaluator/utils/objects_filtering.hpp"
2223

2324
#include <rclcpp/time.hpp>
2425

@@ -118,9 +119,9 @@ class MetricsCalculator
118119
void deleteOldObjects(const rclcpp::Time stamp);
119120

120121
// Calculate metrics
121-
MetricStatMap calcLateralDeviationMetrics(const PredictedObjects & objects) const;
122-
MetricStatMap calcYawDeviationMetrics(const PredictedObjects & objects) const;
123-
MetricStatMap calcPredictedPathDeviationMetrics(const PredictedObjects & objects) const;
122+
MetricStatMap calcLateralDeviationMetrics(const ClassObjectsMap & class_objects_map) const;
123+
MetricStatMap calcYawDeviationMetrics(const ClassObjectsMap & class_objects_map) const;
124+
MetricStatMap calcPredictedPathDeviationMetrics(const ClassObjectsMap & class_objects_map) const;
124125
Stat<double> calcPredictedPathDeviationMetrics(
125126
const PredictedObjects & objects, const double time_horizon) const;
126127

evaluator/perception_online_evaluator/include/perception_online_evaluator/utils/objects_filtering.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ using autoware_auto_perception_msgs::msg::ObjectClassification;
3737
using autoware_auto_perception_msgs::msg::PredictedObject;
3838
using autoware_auto_perception_msgs::msg::PredictedObjects;
3939

40+
using ClassObjectsMap = std::unordered_map<uint8_t, PredictedObjects>;
41+
4042
std::uint8_t getHighestProbLabel(const std::vector<ObjectClassification> & classification);
4143

4244
/**
@@ -105,6 +107,14 @@ void filterObjects(PredictedObjects & objects, Func filter)
105107
filterObjects(objects, removed_objects, filter);
106108
}
107109

110+
/**
111+
* @brief Separates the provided objects based on their classification.
112+
*
113+
* @param objects The predicted objects to be separated.
114+
* @return A map of objects separated by their classification.
115+
*/
116+
ClassObjectsMap separateObjectsByClass(const PredictedObjects & objects);
117+
108118
/**
109119
* @brief Filters the provided objects based on their classification.
110120
*

evaluator/perception_online_evaluator/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<depend>libgoogle-glog-dev</depend>
2525
<depend>motion_utils</depend>
2626
<depend>nav_msgs</depend>
27+
<depend>object_recognition_utils</depend>
2728
<depend>pluginlib</depend>
2829
<depend>rclcpp</depend>
2930
<depend>rclcpp_components</depend>

evaluator/perception_online_evaluator/src/metrics_calculator.cpp

+54-47
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
#include "perception_online_evaluator/metrics_calculator.hpp"
1616

1717
#include "motion_utils/trajectory/trajectory.hpp"
18-
#include "perception_online_evaluator/utils/objects_filtering.hpp"
18+
#include "object_recognition_utils/object_recognition_utils.hpp"
1919
#include "tier4_autoware_utils/geometry/geometry.hpp"
2020

2121
#include <tier4_autoware_utils/ros/uuid_helper.hpp>
2222

2323
namespace perception_diagnostics
2424
{
25+
using object_recognition_utils::convertLabelToString;
26+
2527
std::optional<MetricStatMap> MetricsCalculator::calculate(const Metric & metric) const
2628
{
2729
if (object_map_.empty()) {
@@ -35,14 +37,14 @@ std::optional<MetricStatMap> MetricsCalculator::calculate(const Metric & metric)
3537
return {};
3638
}
3739
const auto target_objects = getObjectsByStamp(target_stamp);
38-
40+
const ClassObjectsMap class_objects_map = separateObjectsByClass(target_objects);
3941
switch (metric) {
4042
case Metric::lateral_deviation:
41-
return calcLateralDeviationMetrics(target_objects);
43+
return calcLateralDeviationMetrics(class_objects_map);
4244
case Metric::yaw_deviation:
43-
return calcYawDeviationMetrics(target_objects);
45+
return calcYawDeviationMetrics(class_objects_map);
4446
case Metric::predicted_path_deviation:
45-
return calcPredictedPathDeviationMetrics(target_objects);
47+
return calcPredictedPathDeviationMetrics(class_objects_map);
4648
default:
4749
return {};
4850
}
@@ -155,65 +157,70 @@ PredictedObjects MetricsCalculator::getObjectsByStamp(const rclcpp::Time stamp)
155157
return objects;
156158
}
157159

158-
MetricStatMap MetricsCalculator::calcLateralDeviationMetrics(const PredictedObjects & objects) const
160+
MetricStatMap MetricsCalculator::calcLateralDeviationMetrics(
161+
const ClassObjectsMap & class_objects_map) const
159162
{
160-
Stat<double> stat{};
161-
const auto stamp = rclcpp::Time(objects.header.stamp);
162-
163-
for (const auto & object : objects.objects) {
164-
const auto uuid = tier4_autoware_utils::toHexString(object.object_id);
165-
if (!hasPassedTime(uuid, stamp)) {
166-
continue;
167-
}
168-
const auto object_pose = object.kinematics.initial_pose_with_covariance.pose;
169-
const auto history_path = history_path_map_.at(uuid).second;
170-
if (history_path.empty()) {
171-
continue;
163+
MetricStatMap metric_stat_map{};
164+
for (const auto & [label, objects] : class_objects_map) {
165+
Stat<double> stat{};
166+
const auto stamp = rclcpp::Time(objects.header.stamp);
167+
for (const auto & object : objects.objects) {
168+
const auto uuid = tier4_autoware_utils::toHexString(object.object_id);
169+
if (!hasPassedTime(uuid, stamp)) {
170+
continue;
171+
}
172+
const auto object_pose = object.kinematics.initial_pose_with_covariance.pose;
173+
const auto history_path = history_path_map_.at(uuid).second;
174+
if (history_path.empty()) {
175+
continue;
176+
}
177+
stat.add(metrics::calcLateralDeviation(history_path, object_pose));
172178
}
173-
stat.add(metrics::calcLateralDeviation(history_path, object_pose));
179+
metric_stat_map["lateral_deviation_" + convertLabelToString(label)] = stat;
174180
}
175-
176-
MetricStatMap metric_stat_map;
177-
metric_stat_map["lateral_deviation"] = stat;
178181
return metric_stat_map;
179182
}
180183

181-
MetricStatMap MetricsCalculator::calcYawDeviationMetrics(const PredictedObjects & objects) const
184+
MetricStatMap MetricsCalculator::calcYawDeviationMetrics(
185+
const ClassObjectsMap & class_objects_map) const
182186
{
183-
Stat<double> stat{};
184-
const auto stamp = rclcpp::Time(objects.header.stamp);
185-
for (const auto & object : objects.objects) {
186-
const auto uuid = tier4_autoware_utils::toHexString(object.object_id);
187-
if (!hasPassedTime(uuid, stamp)) {
188-
continue;
189-
}
190-
const auto object_pose = object.kinematics.initial_pose_with_covariance.pose;
191-
const auto history_path = history_path_map_.at(uuid).second;
192-
if (history_path.empty()) {
193-
continue;
187+
MetricStatMap metric_stat_map{};
188+
for (const auto & [label, objects] : class_objects_map) {
189+
Stat<double> stat{};
190+
const auto stamp = rclcpp::Time(objects.header.stamp);
191+
for (const auto & object : objects.objects) {
192+
const auto uuid = tier4_autoware_utils::toHexString(object.object_id);
193+
if (!hasPassedTime(uuid, stamp)) {
194+
continue;
195+
}
196+
const auto object_pose = object.kinematics.initial_pose_with_covariance.pose;
197+
const auto history_path = history_path_map_.at(uuid).second;
198+
if (history_path.empty()) {
199+
continue;
200+
}
201+
stat.add(metrics::calcYawDeviation(history_path, object_pose));
194202
}
195-
stat.add(metrics::calcYawDeviation(history_path, object_pose));
203+
metric_stat_map["yaw_deviation_" + convertLabelToString(label)] = stat;
196204
}
197-
198-
MetricStatMap metric_stat_map;
199-
metric_stat_map["yaw_deviation"] = stat;
200205
return metric_stat_map;
201206
}
202207

203208
MetricStatMap MetricsCalculator::calcPredictedPathDeviationMetrics(
204-
const PredictedObjects & objects) const
209+
const ClassObjectsMap & class_objects_map) const
205210
{
206211
const auto time_horizons = parameters_->prediction_time_horizons;
207212

208-
MetricStatMap metric_stat_map;
209-
for (const double time_horizon : time_horizons) {
210-
const auto stat = calcPredictedPathDeviationMetrics(objects, time_horizon);
211-
std::ostringstream stream;
212-
stream << std::fixed << std::setprecision(2) << time_horizon;
213-
std::string time_horizon_str = stream.str();
214-
metric_stat_map["predicted_path_deviation_" + time_horizon_str] = stat;
213+
MetricStatMap metric_stat_map{};
214+
for (const auto & [label, objects] : class_objects_map) {
215+
for (const double time_horizon : time_horizons) {
216+
const auto stat = calcPredictedPathDeviationMetrics(objects, time_horizon);
217+
std::ostringstream stream;
218+
stream << std::fixed << std::setprecision(2) << time_horizon;
219+
std::string time_horizon_str = stream.str();
220+
metric_stat_map
221+
["predicted_path_deviation_" + convertLabelToString(label) + "_" + time_horizon_str] = stat;
222+
}
215223
}
216-
217224
return metric_stat_map;
218225
}
219226

evaluator/perception_online_evaluator/src/utils/objects_filtering.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ bool isTargetObjectType(
8383
(t == ObjectClassification::PEDESTRIAN && target_object_types.check_pedestrian));
8484
}
8585

86+
ClassObjectsMap separateObjectsByClass(const PredictedObjects & objects)
87+
{
88+
ClassObjectsMap separated_objects;
89+
for (const auto & object : objects.objects) {
90+
const auto label = getHighestProbLabel(object.classification);
91+
separated_objects[label].objects.push_back(object);
92+
separated_objects[label].header = objects.header;
93+
}
94+
return separated_objects;
95+
}
96+
8697
void filterObjectsByClass(
8798
PredictedObjects & objects, const ObjectTypesToCheck & target_object_types)
8899
{

0 commit comments

Comments
 (0)