diff --git a/evaluator/segmentation_evaluator/README.md b/evaluator/segmentation_evaluator/README.md index 173b8501da1fb..ae7891f620211 100644 --- a/evaluator/segmentation_evaluator/README.md +++ b/evaluator/segmentation_evaluator/README.md @@ -1,3 +1,3 @@ # Segmentation Evaluator -TBD \ No newline at end of file +TBD diff --git a/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/metric.hpp b/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/metric.hpp index 90d81245225c9..1347957a29c05 100644 --- a/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/metric.hpp +++ b/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/metric.hpp @@ -31,16 +31,13 @@ enum class Metric { }; static const std::unordered_map str_to_metric = { - {"segment_stat", Metric::segment_stat} -}; + {"segment_stat", Metric::segment_stat}}; static const std::unordered_map metric_to_str = { - {Metric::segment_stat, "segment_stat"} -}; + {Metric::segment_stat, "segment_stat"}}; // Metrics descriptions static const std::unordered_map metric_descriptions = { - {Metric::segment_stat, "segment_stat [percentage]"} -}; + {Metric::segment_stat, "segment_stat [percentage]"}}; namespace details { diff --git a/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/segmentation_metrics.hpp b/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/segmentation_metrics.hpp index 16510b18477ae..98b0c5611052c 100644 --- a/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/segmentation_metrics.hpp +++ b/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics/segmentation_metrics.hpp @@ -43,7 +43,8 @@ Stat updatePclStats( * @return calculated statistics */ std::vector computeConfusionMatrix( - const PointCloud2 & pcl, const PointCloud2 & pcl_gt_ground, const PointCloud2 & pcl_gt_obj, PointCloud2 & pcl_no_ex); + const PointCloud2 & pcl, const PointCloud2 & pcl_gt_ground, const PointCloud2 & pcl_gt_obj, + PointCloud2 & pcl_no_ex); } // namespace metrics } // namespace segmentation_diagnostics diff --git a/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics_calculator.hpp b/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics_calculator.hpp index 2e14459b64c9f..0f402a78a136b 100644 --- a/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics_calculator.hpp +++ b/evaluator/segmentation_evaluator/include/segmentation_evaluator/metrics_calculator.hpp @@ -54,7 +54,8 @@ class MetricsCalculator */ Stat updateStat( const Stat stat_prev, const Metric metric, const PointCloud2 & pcl, - const PointCloud2 & pcl_gt_ground, const PointCloud2 & pcl_gt_obj, PointCloud2 & pcl_no_ex) const; + const PointCloud2 & pcl_gt_ground, const PointCloud2 & pcl_gt_obj, + PointCloud2 & pcl_no_ex) const; }; // class MetricsCalculator } // namespace segmentation_diagnostics diff --git a/evaluator/segmentation_evaluator/include/segmentation_evaluator/parameters.hpp b/evaluator/segmentation_evaluator/include/segmentation_evaluator/parameters.hpp index 443133260cd34..389a7be5697a6 100644 --- a/evaluator/segmentation_evaluator/include/segmentation_evaluator/parameters.hpp +++ b/evaluator/segmentation_evaluator/include/segmentation_evaluator/parameters.hpp @@ -27,8 +27,8 @@ namespace segmentation_diagnostics struct Parameters { std::array(Metric::SIZE)> metrics{}; // default values to false -}; // struct Parameters +}; // struct Parameters -} // namespace localiaztion_diagnostics +} // namespace segmentation_diagnostics #endif // SEGMENTATION_EVALUATOR__PARAMETERS_HPP_ diff --git a/evaluator/segmentation_evaluator/include/segmentation_evaluator/segmentation_evaluator_node.hpp b/evaluator/segmentation_evaluator/include/segmentation_evaluator/segmentation_evaluator_node.hpp index b40e533bada78..1e5bd2911c85b 100644 --- a/evaluator/segmentation_evaluator/include/segmentation_evaluator/segmentation_evaluator_node.hpp +++ b/evaluator/segmentation_evaluator/include/segmentation_evaluator/segmentation_evaluator_node.hpp @@ -71,7 +71,8 @@ class SegmentationEvaluatorNode : public rclcpp::Node message_filters::Subscriber pcl_sub_, pcl_gt_ground_sub_, pcl_gt_obj_sub_; rclcpp::Publisher::SharedPtr pcl_no_ex_pub_; - typedef message_filters::sync_policies::ApproximateTime SyncPolicy; + typedef message_filters::sync_policies::ApproximateTime + SyncPolicy; typedef message_filters::Synchronizer SyncExact; SyncExact sync_; rclcpp::Publisher::SharedPtr metrics_pub_; @@ -91,4 +92,4 @@ class SegmentationEvaluatorNode : public rclcpp::Node }; } // namespace segmentation_diagnostics -#endif // SEGMENTATION_EVALUATOR__MOTION_EVALUATOR_NODE_HPP_ +#endif // SEGMENTATION_EVALUATOR__SEGMENTATION_EVALUATOR_NODE_HPP_ diff --git a/evaluator/segmentation_evaluator/include/segmentation_evaluator/stat.hpp b/evaluator/segmentation_evaluator/include/segmentation_evaluator/stat.hpp index c555bc6f4bb32..fc1b6320f5511 100644 --- a/evaluator/segmentation_evaluator/include/segmentation_evaluator/stat.hpp +++ b/evaluator/segmentation_evaluator/include/segmentation_evaluator/stat.hpp @@ -66,16 +66,20 @@ class Stat */ void printConfMat() { - std::cout << std::left << std::fixed << - " ┌──────────────┬─────────────────────────────┐\n" - " │ │ Predicted values │\n" - " │ Confusion ├──────────────┬──────────────┤\n" - " │ matrix │ object │ ground │\n" - "┌───────────┼──────────────┼──────────────┼──────────────┤\n" - "│ Actual │ object │" << std::setw(14) << tp_ << "│" << std::setw(13) << fn_ << " │\n" - "│ values ├──────────────┼──────────────┼──────────────┤\n" - "│ │ ground │" << std::setw(14) << fp_ << "│" << std::setw(13) << tn_ << " │\n" - "└───────────┴──────────────┴──────────────┴──────────────┘\n"; + std::cout << std::left << std::fixed + << " ┌──────────────┬─────────────────────────────┐\n" + " │ │ Predicted values │\n" + " │ Confusion ├──────────────┬──────────────┤\n" + " │ matrix │ object │ ground │\n" + "┌───────────┼──────────────┼──────────────┼──────────────┤\n" + "│ Actual │ object │" + << std::setw(14) << tp_ << "│" << std::setw(13) << fn_ + << " │\n" + "│ values ├──────────────┼──────────────┼──────────────┤\n" + "│ │ ground │" + << std::setw(14) << fp_ << "│" << std::setw(13) << tn_ + << " │\n" + "└───────────┴──────────────┴──────────────┴──────────────┘\n"; } /** @@ -83,37 +87,43 @@ class Stat */ void printConfMatAccu() { - std::cout << std::left << std::fixed << - " ┌──────────────┬─────────────────────────────┐\n" - " │ │ Predicted values │\n" - " │ Confusion ├──────────────┬──────────────┤\n" - " │ matrix │ object │ ground │\n" - "┌───────────┼──────────────┼──────────────┼──────────────┤\n" - "│ Actual │ object │" << std::setw(14) << tp_accu_ << "│" << std::setw(13) << fn_accu_ << " │\n" - "│ values ├──────────────┼──────────────┼──────────────┤\n" - "│ │ ground │" << std::setw(14) << fp_accu_ << "│" << std::setw(13) << tn_accu_ << " │\n" - "└───────────┴──────────────┴──────────────┴──────────────┘\n"; + std::cout << std::left << std::fixed + << " ┌──────────────┬─────────────────────────────┐\n" + " │ │ Predicted values │\n" + " │ Confusion ├──────────────┬──────────────┤\n" + " │ matrix │ object │ ground │\n" + "┌───────────┼──────────────┼──────────────┼──────────────┤\n" + "│ Actual │ object │" + << std::setw(14) << tp_accu_ << "│" << std::setw(13) << fn_accu_ + << " │\n" + "│ values ├──────────────┼──────────────┼──────────────┤\n" + "│ │ ground │" + << std::setw(14) << fp_accu_ << "│" << std::setw(13) << tn_accu_ + << " │\n" + "└───────────┴──────────────┴──────────────┴──────────────┘\n"; } - /** + /** * @brief set confusion matrix */ - void setConfustionMatPerCloud(const std::vector & conf_mat) { + void setConfustionMatPerCloud(const std::vector & conf_mat) + { tp_ = conf_mat[0]; fn_ = conf_mat[1]; fp_ = conf_mat[2]; - tn_ = conf_mat[3]; + tn_ = conf_mat[3]; accumulateConfustionMat(conf_mat); } - /** + /** * @brief accumulate confusion matrix */ - void accumulateConfustionMat(const std::vector & conf_mat) { + void accumulateConfustionMat(const std::vector & conf_mat) + { tp_accu_ += conf_mat[0]; fn_accu_ += conf_mat[1]; fp_accu_ += conf_mat[2]; - tn_accu_ += conf_mat[3]; + tn_accu_ += conf_mat[3]; } /** diff --git a/evaluator/segmentation_evaluator/package.xml b/evaluator/segmentation_evaluator/package.xml index 80350e33275f6..6425ac2332d78 100644 --- a/evaluator/segmentation_evaluator/package.xml +++ b/evaluator/segmentation_evaluator/package.xml @@ -11,7 +11,7 @@ ament_cmake_auto autoware_cmake - + autoware_auto_perception_msgs autoware_auto_planning_msgs diagnostic_msgs @@ -24,7 +24,7 @@ tf2 tf2_ros tier4_autoware_utils - + ament_cmake_gtest ament_lint_auto autoware_lint_common diff --git a/evaluator/segmentation_evaluator/src/metrics/segmentation_metrics.cpp b/evaluator/segmentation_evaluator/src/metrics/segmentation_metrics.cpp index f2bfad4d8d0c5..0f09753774605 100644 --- a/evaluator/segmentation_evaluator/src/metrics/segmentation_metrics.cpp +++ b/evaluator/segmentation_evaluator/src/metrics/segmentation_metrics.cpp @@ -14,18 +14,18 @@ #include "segmentation_evaluator/metrics/segmentation_metrics.hpp" -#include "tier4_autoware_utils/tier4_autoware_utils.hpp" - -#include -#include -#include #include "rclcpp/serialization.hpp" #include "rclcpp/serialized_message.hpp" +#include "tier4_autoware_utils/tier4_autoware_utils.hpp" #include #include "boost/container_hash/hash.hpp" +#include +#include +#include + namespace segmentation_diagnostics { namespace metrics @@ -50,17 +50,15 @@ Stat updatePclStats( return stat; } -float r(float v) -{ - return floor(v*1000.0) / 1000.0; -} +float r(float v) { return floor(v * 1000.0) / 1000.0; } std::vector computeConfusionMatrix( const PointCloud2 & pcl_to_eval, const PointCloud2 & pcl_gt_ground, const PointCloud2 & pcl_gt_obj, PointCloud2 & pcl_no_ex) { // std::cout << pcl_gt_ground.row_step << " + " << pcl_gt_obj.row_step << " = " - // << pcl_gt_ground.row_step + pcl_gt_obj.row_step << " !eval: " << pcl_to_eval.row_step + // << pcl_gt_ground.row_step + pcl_gt_obj.row_step << " !eval: " << + // pcl_to_eval.row_step // << std::endl; pcl::PointCloud::Ptr pcl_no_ex_xyz(new pcl::PointCloud); pcl_no_ex_xyz->points.reserve(pcl_to_eval.row_step); @@ -120,9 +118,9 @@ std::vector computeConfusionMatrix( // std::cout << "ZEROS in pred: " << cnt_zero << "\n"; // std::cout << "NONEX in pred: " << cnt_non_ex << "\n"; - std::cout << "Accuracy: " << float(tp+tn)/float(tp+tn+fn+fp) << "\n"; - std::cout << "Precision: " << float(tp)/float(tp+fp) << "\n"; - std::cout << "Recall: " << float(tp)/float(tp+fn) << "\n"; + std::cout << "Accuracy: " << float(tp + tn) / float(tp + tn + fn + fp) << "\n"; + std::cout << "Precision: " << float(tp) / float(tp + fp) << "\n"; + std::cout << "Recall: " << float(tp) / float(tp + fn) << "\n"; pcl::toROSMsg(*pcl_no_ex_xyz, pcl_no_ex); pcl_no_ex.set__header(pcl_to_eval.header); diff --git a/evaluator/segmentation_evaluator/src/segmentation_evaluator_node.cpp b/evaluator/segmentation_evaluator/src/segmentation_evaluator_node.cpp index 4529c73ede726..582eabda8fad6 100644 --- a/evaluator/segmentation_evaluator/src/segmentation_evaluator_node.cpp +++ b/evaluator/segmentation_evaluator/src/segmentation_evaluator_node.cpp @@ -41,7 +41,6 @@ SegmentationEvaluatorNode::SegmentationEvaluatorNode(const rclcpp::NodeOptions & pcl_no_ex_pub_ = this->create_publisher("~/pcl_no_ex", rclcpp::SensorDataQoS()); - output_file_str_ = declare_parameter("output_file"); if (output_file_str_.empty()) { RCLCPP_INFO( @@ -89,8 +88,8 @@ void SegmentationEvaluatorNode::syncCallback( metrics_msg.header.stamp = now(); PointCloud2 pcl_no_ex; for (Metric metric : metrics_) { - metrics_dict_[metric] = - metrics_calculator_.updateStat(metrics_dict_[metric], metric, *msg, *msg_gt_ground, *msg_gt_obj, pcl_no_ex); + metrics_dict_[metric] = metrics_calculator_.updateStat( + metrics_dict_[metric], metric, *msg, *msg_gt_ground, *msg_gt_obj, pcl_no_ex); // std::cout << metrics_dict_[metric] << "\n"; // std::cout << "metric dict count" << metrics_dict_[metric].count() << "\n"; if (metrics_dict_[metric].count() > 0) { diff --git a/evaluator/segmentation_evaluator/test/test_segmentation_evaluator_node.cpp b/evaluator/segmentation_evaluator/test/test_segmentation_evaluator_node.cpp index f1c149e10607f..f2644bf8f1fc0 100644 --- a/evaluator/segmentation_evaluator/test/test_segmentation_evaluator_node.cpp +++ b/evaluator/segmentation_evaluator/test/test_segmentation_evaluator_node.cpp @@ -67,7 +67,9 @@ class EvalTest : public ::testing::Test tf_broadcaster_ = std::make_unique(dummy_node); } - ~EvalTest() override { /*rclcpp::shutdown();*/ } + ~EvalTest() override + { /*rclcpp::shutdown();*/ + } void setTargetMetric(segmentation_diagnostics::Metric metric) {