curfil  ..
 All Classes Functions Variables Typedefs Friends Groups Pages
export.h
1 #ifndef CURFIL_EXPORT_HPP
2 #define CURFIL_EXPORT_HPP
3 
4 #include <boost/property_tree/ptree.hpp>
5 #include <string>
6 
7 #include "random_forest_image.h"
8 
9 namespace curfil {
10 
18 
19 
20 public:
21 
30  RandomTreeExport(const TrainingConfiguration& configuration, const std::string& outputFolder,
31  const std::string& trainingFolder, bool verbose);
32 
39  void writeJSON(const RandomTreeImage& tree, size_t treeNr) const;
40 
47  template<class TreeEnsemble>
48  void writeJSON(const TreeEnsemble& ensemble) const {
49 
50  CURFIL_INFO("writing tree files to " << outputFolder << " (verbose: " << verbose << ")");
51 
52  for (size_t treeNr = 0; treeNr < ensemble.getTrees().size(); treeNr++) {
53  writeJSON(*(ensemble.getTree(treeNr)), treeNr);
54  }
55 
56  CURFIL_INFO("wrote JSON files to " << outputFolder);
57  }
58 
59 private:
60  static std::string spaces(int level);
61 
62  static void writeXY(boost::property_tree::ptree& pt, const std::string& name, const XY& xy);
63 
64  static void writeFeatureDetails(boost::property_tree::ptree& pt, const ImageFeatureFunction& feature);
65 
66  static std::vector<std::map<std::string, std::string> > parseProcCpuInfo();
67 
68  static int getPhysicalCores();
69 
70  static int getPhysicalCpus();
71 
72  template<class T>
73  static boost::property_tree::ptree toPropertyTree(const std::vector<T>& input) {
74  boost::property_tree::ptree propertyTree;
75  for (const auto& v : input) {
76  propertyTree.push_back(std::make_pair("", boost::lexical_cast<std::string>(v)));
77  }
78  return propertyTree;
79  }
80 
81  static boost::property_tree::ptree getProcessorModelNames();
82 
83  void writeTree(boost::property_tree::ptree& pt, const RandomTree<PixelInstance, ImageFeatureFunction>& tree) const;
84 
85  void writeTree(boost::property_tree::ptree& pt, const RandomTreeImage& tree) const;
86 
87 private:
88 
89  const boost::posix_time::ptime date;
90  const TrainingConfiguration& configuration;
91  const std::string outputFolder;
92  const std::string trainingFolder;
93  const bool verbose;
94 
95 };
96 
97 }
98 
99 #endif