Skip to content

Commit

Permalink
ci(pre-commit): autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Aug 16, 2022
1 parent a8510d2 commit 0c2323d
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 58 deletions.
2 changes: 1 addition & 1 deletion evaluator/segmentation_evaluator/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Segmentation Evaluator

TBD
TBD
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ enum class Metric {
};

static const std::unordered_map<std::string, Metric> str_to_metric = {
{"segment_stat", Metric::segment_stat}
};
{"segment_stat", Metric::segment_stat}};
static const std::unordered_map<Metric, std::string> metric_to_str = {
{Metric::segment_stat, "segment_stat"}
};
{Metric::segment_stat, "segment_stat"}};

// Metrics descriptions
static const std::unordered_map<Metric, std::string> metric_descriptions = {
{Metric::segment_stat, "segment_stat [percentage]"}
};
{Metric::segment_stat, "segment_stat [percentage]"}};

namespace details
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Stat<double> updatePclStats(
* @return calculated statistics
*/
std::vector<int> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class MetricsCalculator
*/
Stat<double> updateStat(
const Stat<double> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace segmentation_diagnostics
struct Parameters
{
std::array<bool, static_cast<size_t>(Metric::SIZE)> metrics{}; // default values to false
}; // struct Parameters
}; // struct Parameters

} // namespace localiaztion_diagnostics
} // namespace segmentation_diagnostics

#endif // SEGMENTATION_EVALUATOR__PARAMETERS_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class SegmentationEvaluatorNode : public rclcpp::Node
message_filters::Subscriber<PointCloud2> pcl_sub_, pcl_gt_ground_sub_, pcl_gt_obj_sub_;
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pcl_no_ex_pub_;

typedef message_filters::sync_policies::ApproximateTime<PointCloud2, PointCloud2, PointCloud2> SyncPolicy;
typedef message_filters::sync_policies::ApproximateTime<PointCloud2, PointCloud2, PointCloud2>
SyncPolicy;
typedef message_filters::Synchronizer<SyncPolicy> SyncExact;
SyncExact sync_;
rclcpp::Publisher<DiagnosticArray>::SharedPtr metrics_pub_;
Expand All @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -66,54 +66,64 @@ 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";
}

/**
* @brief Print accumulated confusion matrix
*/
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<int> & conf_mat) {
void setConfustionMatPerCloud(const std::vector<int> & 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<int> & conf_mat) {
void accumulateConfustionMat(const std::vector<int> & 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];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions evaluator/segmentation_evaluator/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>

<build_depend>autoware_cmake</build_depend>

<depend>autoware_auto_perception_msgs</depend>
<depend>autoware_auto_planning_msgs</depend>
<depend>diagnostic_msgs</depend>
Expand All @@ -24,7 +24,7 @@
<depend>tf2</depend>
<depend>tf2_ros</depend>
<depend>tier4_autoware_utils</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

#include "segmentation_evaluator/metrics/segmentation_metrics.hpp"

#include "tier4_autoware_utils/tier4_autoware_utils.hpp"

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include "rclcpp/serialization.hpp"
#include "rclcpp/serialized_message.hpp"
#include "tier4_autoware_utils/tier4_autoware_utils.hpp"

#include <sensor_msgs/point_cloud2_iterator.hpp>

#include "boost/container_hash/hash.hpp"

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>

namespace segmentation_diagnostics
{
namespace metrics
Expand All @@ -50,17 +50,15 @@ Stat<double> 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<int> 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<pcl::PointXYZ>::Ptr pcl_no_ex_xyz(new pcl::PointCloud<pcl::PointXYZ>);
pcl_no_ex_xyz->points.reserve(pcl_to_eval.row_step);
Expand Down Expand Up @@ -120,9 +118,9 @@ std::vector<int> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ SegmentationEvaluatorNode::SegmentationEvaluatorNode(const rclcpp::NodeOptions &

pcl_no_ex_pub_ = this->create_publisher<PointCloud2>("~/pcl_no_ex", rclcpp::SensorDataQoS());


output_file_str_ = declare_parameter<std::string>("output_file");
if (output_file_str_.empty()) {
RCLCPP_INFO(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class EvalTest : public ::testing::Test
tf_broadcaster_ = std::make_unique<tf2_ros::TransformBroadcaster>(dummy_node);
}

~EvalTest() override { /*rclcpp::shutdown();*/ }
~EvalTest() override
{ /*rclcpp::shutdown();*/
}

void setTargetMetric(segmentation_diagnostics::Metric metric)
{
Expand Down

0 comments on commit 0c2323d

Please sign in to comment.