Skip to content

Commit 272f5d0

Browse files
authored
Revert "feat(perception_online_evaluator): add metric_value not only stat (#7…"
This reverts commit fe30833.
1 parent 98cc9f2 commit 272f5d0

File tree

6 files changed

+19
-61
lines changed

6 files changed

+19
-61
lines changed

evaluator/perception_online_evaluator/include/perception_online_evaluator/metrics/metric.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <iostream>
2121
#include <string>
2222
#include <unordered_map>
23-
#include <variant>
2423
#include <vector>
2524

2625
namespace perception_diagnostics
@@ -37,11 +36,7 @@ enum class Metric {
3736
SIZE,
3837
};
3938

40-
// Each metric has a different return type. (statistic or just a one value etc).
41-
// To handle them all in the MetricsCalculator::calculate function, define MetricsMap as a variant
4239
using MetricStatMap = std::unordered_map<std::string, Stat<double>>;
43-
using MetricValueMap = std::unordered_map<std::string, double>;
44-
using MetricsMap = std::variant<MetricStatMap, MetricValueMap>;
4540

4641
struct PredictedPathDeviationMetrics
4742
{

evaluator/perception_online_evaluator/include/perception_online_evaluator/metrics_calculator.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class MetricsCalculator
9696
* @param [in] metric Metric enum value
9797
* @return map of string describing the requested metric and the calculated value
9898
*/
99-
std::optional<MetricsMap> calculate(const Metric & metric) const;
99+
std::optional<MetricStatMap> calculate(const Metric & metric) const;
100100

101101
/**
102102
* @brief set the dynamic objects used to calculate obstacle metrics
@@ -143,7 +143,7 @@ class MetricsCalculator
143143
PredictedPathDeviationMetrics calcPredictedPathDeviationMetrics(
144144
const PredictedObjects & objects, const double time_horizon) const;
145145
MetricStatMap calcYawRateMetrics(const ClassObjectsMap & class_objects_map) const;
146-
MetricValueMap calcObjectsCountMetrics() const;
146+
MetricStatMap calcObjectsCountMetrics() const;
147147

148148
bool hasPassedTime(const rclcpp::Time stamp) const;
149149
bool hasPassedTime(const std::string uuid, const rclcpp::Time stamp) const;

evaluator/perception_online_evaluator/include/perception_online_evaluator/perception_online_evaluator_node.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class PerceptionOnlineEvaluatorNode : public rclcpp::Node
6161

6262
DiagnosticStatus generateDiagnosticStatus(
6363
const std::string metric, const Stat<double> & metric_stat) const;
64-
DiagnosticStatus generateDiagnosticStatus(
65-
const std::string metric, const double metric_value) const;
6664

6765
private:
6866
// Subscribers and publishers

evaluator/perception_online_evaluator/src/metrics_calculator.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace perception_diagnostics
2626
using object_recognition_utils::convertLabelToString;
2727
using tier4_autoware_utils::inverseTransformPoint;
2828

29-
std::optional<MetricsMap> MetricsCalculator::calculate(const Metric & metric) const
29+
std::optional<MetricStatMap> MetricsCalculator::calculate(const Metric & metric) const
3030
{
3131
// clang-format off
3232
const bool use_past_objects = metric == Metric::lateral_deviation ||
@@ -455,14 +455,15 @@ MetricStatMap MetricsCalculator::calcYawRateMetrics(const ClassObjectsMap & clas
455455
return metric_stat_map;
456456
}
457457

458-
MetricValueMap MetricsCalculator::calcObjectsCountMetrics() const
458+
MetricStatMap MetricsCalculator::calcObjectsCountMetrics() const
459459
{
460-
MetricValueMap metric_stat_map;
460+
MetricStatMap metric_stat_map;
461461
// calculate the average number of objects in the detection area in all past frames
462462
const auto overall_average_count = detection_counter_.getOverallAverageCount();
463463
for (const auto & [label, range_and_count] : overall_average_count) {
464464
for (const auto & [range, count] : range_and_count) {
465-
metric_stat_map["average_objects_count_" + convertLabelToString(label) + "_" + range] = count;
465+
metric_stat_map["average_objects_count_" + convertLabelToString(label) + "_" + range].add(
466+
count);
466467
}
467468
}
468469
// calculate the average number of objects in the detection area in the past
@@ -471,16 +472,17 @@ MetricValueMap MetricsCalculator::calcObjectsCountMetrics() const
471472
detection_counter_.getAverageCount(parameters_->objects_count_window_seconds);
472473
for (const auto & [label, range_and_count] : average_count) {
473474
for (const auto & [range, count] : range_and_count) {
474-
metric_stat_map
475-
["interval_average_objects_count_" + convertLabelToString(label) + "_" + range] = count;
475+
metric_stat_map["interval_average_objects_count_" + convertLabelToString(label) + "_" + range]
476+
.add(count);
476477
}
477478
}
478479

479480
// calculate the total number of objects in the detection area
480481
const auto total_count = detection_counter_.getTotalCount();
481482
for (const auto & [label, range_and_count] : total_count) {
482483
for (const auto & [range, count] : range_and_count) {
483-
metric_stat_map["total_objects_count_" + convertLabelToString(label) + "_" + range] = count;
484+
metric_stat_map["total_objects_count_" + convertLabelToString(label) + "_" + range].add(
485+
count);
484486
}
485487
}
486488

evaluator/perception_online_evaluator/src/perception_online_evaluator_node.cpp

+7-32
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,16 @@ void PerceptionOnlineEvaluatorNode::publishMetrics()
6969

7070
// calculate metrics
7171
for (const Metric & metric : parameters_->metrics) {
72-
const auto metric_result = metrics_calculator_.calculate(Metric(metric));
73-
if (!metric_result.has_value()) {
72+
const auto metric_stat_map = metrics_calculator_.calculate(Metric(metric));
73+
if (!metric_stat_map.has_value()) {
7474
continue;
7575
}
7676

77-
std::visit(
78-
[&metrics_msg, this](auto && arg) {
79-
using T = std::decay_t<decltype(arg)>;
80-
for (const auto & [metric, value] : arg) {
81-
if constexpr (std::is_same_v<T, MetricStatMap>) {
82-
if (value.count() > 0) {
83-
metrics_msg.status.push_back(generateDiagnosticStatus(metric, value));
84-
}
85-
} else if constexpr (std::is_same_v<T, MetricValueMap>) {
86-
metrics_msg.status.push_back(generateDiagnosticStatus(metric, value));
87-
}
88-
}
89-
},
90-
metric_result.value());
77+
for (const auto & [metric, stat] : metric_stat_map.value()) {
78+
if (stat.count() > 0) {
79+
metrics_msg.status.push_back(generateDiagnosticStatus(metric, stat));
80+
}
81+
}
9182
}
9283

9384
// publish metrics
@@ -120,22 +111,6 @@ DiagnosticStatus PerceptionOnlineEvaluatorNode::generateDiagnosticStatus(
120111
return status;
121112
}
122113

123-
DiagnosticStatus PerceptionOnlineEvaluatorNode::generateDiagnosticStatus(
124-
const std::string metric, const double value) const
125-
{
126-
DiagnosticStatus status;
127-
128-
status.level = status.OK;
129-
status.name = metric;
130-
131-
diagnostic_msgs::msg::KeyValue key_value;
132-
key_value.key = "metric_value";
133-
key_value.value = std::to_string(value);
134-
status.values.push_back(key_value);
135-
136-
return status;
137-
}
138-
139114
void PerceptionOnlineEvaluatorNode::onObjects(const PredictedObjects::ConstSharedPtr objects_msg)
140115
{
141116
metrics_calculator_.setPredictedObjects(*objects_msg, *tf_buffer_);

evaluator/perception_online_evaluator/test/test_perception_online_evaluator_node.cpp

+1-13
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,7 @@ class EvalTest : public ::testing::Test
141141
[=](const DiagnosticArray::ConstSharedPtr msg) {
142142
const auto it = std::find_if(msg->status.begin(), msg->status.end(), is_target_metric);
143143
if (it != msg->status.end()) {
144-
const auto mean_it = std::find_if(
145-
it->values.begin(), it->values.end(),
146-
[](const auto & key_value) { return key_value.key == "mean"; });
147-
if (mean_it != it->values.end()) {
148-
metric_value_ = boost::lexical_cast<double>(mean_it->value);
149-
} else {
150-
const auto metric_value_it = std::find_if(
151-
it->values.begin(), it->values.end(),
152-
[](const auto & key_value) { return key_value.key == "metric_value"; });
153-
if (metric_value_it != it->values.end()) {
154-
metric_value_ = boost::lexical_cast<double>(metric_value_it->value);
155-
}
156-
}
144+
metric_value_ = boost::lexical_cast<double>(it->values[2].value);
157145
metric_updated_ = true;
158146
}
159147
});

0 commit comments

Comments
 (0)