pose_prediction_tester.cpp
Go to the documentation of this file.
1 
18 #include <ros/ros.h>
22 #include <boost/filesystem.hpp>
23 #include <boost/regex.hpp>
24 #include <boost/algorithm/string/regex.hpp>
25 #include <iostream>
26 #include <fstream>
27 #include <chrono>
28 
30 private:
34 
35  ISM::PosePtr id_pose;
37 
38  void runTest(std::string path_to_db){
39  ROS_INFO("Run Test for database \"%s\"", path_to_db.c_str());
40 
41 
42  ISM::TableHelper* helper = new ISM::TableHelper(path_to_db);
43  std::vector<std::string> pattern_names = helper->getRecordedPatternNames();
44 
45  int set_count = (int) helper->getSetIds().size();
46  int object_count = (int) helper->getRecordedObjectSet(1)->objects.size();
47  //calculate Treesize from modelpatternname
48  int treesize = 0;
49  std::vector<std::string> model_pattern_names = helper->getModelPatternNames();
50  for(size_t j = 0; j < model_pattern_names.size(); j++){
51  std::vector<std::string> tokens;
52  boost::split_regex(tokens, model_pattern_names[j], boost::regex("_sub"));
53  treesize = std::max(treesize, (int)tokens.size());
54  }
55 
56  for(size_t j = 0; j < pattern_names.size(); j++){
57  std::string pattern_name = pattern_names[j];
58  double nn_time = 0;
59  double shortest_path_time = 0;
60  for(int i = 0; i < iteration_; i++){
61  double nn_time_new;
62  double shortest_path_time_new;
63  ROS_INFO("starting iteration %d/%d for %d-%d", i, iteration_, object_count, set_count);
64 
65  ROS_INFO("nnpredictor start");
67  auto t0 = std::chrono::high_resolution_clock::now();
68  nnpredictor_->predictUnfoundPoses(id_pose, pattern_name, 1.0);
69  auto t1 = std::chrono::high_resolution_clock::now();
70  nn_time_new = 1.e-9*std::chrono::duration_cast<std::chrono::nanoseconds>(t1-t0).count();
71  ROS_INFO("nnpredictor end time: %f", nn_time_new);
72 
73  ROS_INFO("sppredictor start");
75  auto t2 = std::chrono::high_resolution_clock::now();
76  sppredictor_->predictUnfoundPoses(id_pose, pattern_name, 1.0);
77  auto t3 = std::chrono::high_resolution_clock::now();
78  shortest_path_time_new = 1.e-9*std::chrono::duration_cast<std::chrono::nanoseconds>(t3-t2).count();
79 
80  ROS_INFO("sppredictor end time: %f", shortest_path_time_new);
81 
82  output_total_file_ << i << "," << object_count << "," << set_count << "," << treesize << "," << nn_time_new << "," << shortest_path_time_new << std::endl;
83  nn_time += nn_time_new;
84  shortest_path_time += shortest_path_time_new;
85  }
86  output_avg_file_ << object_count << "," << set_count << "," << treesize << "," << (nn_time / iteration_) << "," << (shortest_path_time / iteration_) << std::endl;
87 
88  }
89 
90  }
91 
92 public:
94  ros::NodeHandle nh("/pose_prediction_test");
95  id_pose = ISM::PosePtr(new ISM::Pose(new ISM::Point(0, 0, 0), new ISM::Quaternion(0, 0, 0, 1)));
96 
97  //Read Params
98  ROS_INFO("Pose Prediction Tester started");
99  std::string input_path;
100  if(!nh.getParam("input_path", input_path)){
101  ROS_ERROR("Faild to read input path!");
102  return;
103  }
104  ROS_INFO("Input Path: %s", input_path.c_str());
105 
106  std::string output_path;
107  if(!nh.getParam("output_path", output_path)){
108  ROS_ERROR("Faild to read output_path!");
109  return;
110  }
111  ROS_INFO("Output path: %s", output_path.c_str());
112 
113  if(!nh.getParam("iteration", iteration_)){
114  ROS_WARN("Faild to load param iteration, defauting to 10!");
115  iteration_ = 10;
116  }
117  ROS_INFO("Iteratrion: %d", iteration_);
118 
119  output_avg_file_.open (output_path+ "pp_avg.csv");
120  output_avg_file_ << "objects" << "," << "sets" << "," << "treesize" << "," << "nonnormalized" << "," << "shortestpath" << std::endl;
121  output_total_file_.open (output_path + "pp_total.csv");
122  output_total_file_<< "test_run" << "," << "objects" << "," << "sets" << "," << "treesize" << "," << "nonnormalized" << "," << "shortestpath" << std::endl;
123  boost::filesystem::path path_to_db_dir(input_path);
124  std::vector<boost::filesystem::path> paths;
125  std::copy(boost::filesystem::directory_iterator(path_to_db_dir), boost::filesystem::directory_iterator(), std::back_inserter(paths));
126  std::sort(paths.begin(), paths.end());
127  for (std::vector<boost::filesystem::path>::const_iterator i(paths.begin()), i_end(paths.end()); i != i_end; ++i)
128  {
129  if (!boost::filesystem::is_directory(*i))
130  {
131  runTest(i->string());
132 
133  }
134  }
135  output_avg_file_.close();
136  output_total_file_.close();
137  }
138 
139 };
140 
141 
142 
143 int main(int argc, char **argv) {
144  ros::init(argc, argv, "pose_prediction_test");
145  new PosePredictionTester();
146 }
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_WARN(...)
SharedPtr< PaperPredictionNonNormalized > PaperPredictionNonNormalizedPtr
int main(int argc, char **argv)
pose_prediction_ism::ShortestPathPtr sppredictor_
SharedPtr< ShortestPath > ShortestPathPtr
Definition: shortest_path.h:45
void runTest(std::string path_to_db)
#define ROS_INFO(...)
pose_prediction_ism::PaperPredictionNonNormalizedPtr nnpredictor_
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR(...)


asr_lib_pose_prediction_ism
Author(s): Heizmann Heinrich, Heller Florian, Meißner Pascal, Stöckle Patrick
autogenerated on Thu Jan 9 2020 07:19:56