Skip to content

Commit

Permalink
modelinfos
Browse files Browse the repository at this point in the history
  • Loading branch information
laitassou committed Apr 23, 2020
1 parent 4604e65 commit 36fe501
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
2 changes: 2 additions & 0 deletions service/examples/mpg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ int main() {
ModelInfos<float> mInfos("../ModelInfo.txt");
mInfos.show();

mInfos.parse();

// Create Tensors
Tensor input(m, "x");
Tensor prediction(m, "Identity");
Expand Down
96 changes: 96 additions & 0 deletions service/include/ModelInfos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* class ModelInfos.h
* user: laitassou
* description
*/

#pragma once


#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <cassert>
#include <exception>
#include <iostream>
#include <sstream>
#include <string>
#include <map>


template <class T> class ModelInfos
{
public:
struct Stats
{
T mean;
T std;
};

ModelInfos(const std::string & name):input_depth(0)
{

try
{
//std::stringstream ss;
// send your JSON above to the parser below, but populate ss first
//boost::property_tree::ptree pt;

std::ifstream jsonFile(name);
boost::property_tree::read_json(jsonFile, pt_json);

}
catch (std::exception const& e)
{
std::cout<< e.what()<< std::endl;
}
}
const std::string & get(const std::string &label) const
{
auto it = labels.find(label);
if(it == labels.end())
{
return std::string();
}
else{
return it->second;
}
}

size_t get_depth()const
{
return input_depth;
}

void show(void) const
{
using boost::property_tree::ptree;
ptree::const_iterator end = pt_json.end();
for (ptree::const_iterator it = pt_json.begin(); it != end; ++it) {
std::cout << it->first << " :" <<std::endl;
auto row = it->second;
for(auto & rr :row)
std::cout << rr.first << ":" << rr.second.data()<< std::endl;
}
}
void parse(void)
{
using boost::property_tree::ptree;
ptree::const_iterator end = pt_json.end();
for (ptree::const_iterator it = pt_json.begin(); it != end; ++it) {
auto row = it->second;
for(auto & rr :row)
{
input_depth++;
std::cout << rr.first << ", input_depth :" << input_depth <<std::endl;
}
break;

}
}

private:
size_t input_depth;
std::map<std::string,struct Stats> labels;
boost::property_tree::ptree pt_json;
};

0 comments on commit 36fe501

Please sign in to comment.