TFFifoHandler.cxx
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 // TFFifoHander
3 //
4 // A module to evaluate a tensorflow model using FIFO connections to python
5 //
6 // \author $Author: Alex Himmel
7 ////////////////////////////////////////////////////////////////////////
8 
9 #include <iostream>
10 #include <string>
12 
13 namespace tensorflow
14 {
16  fToTF(pset.get<std::string>("PipeToTF")),
17  fFromTF(pset.get<std::string>("PipeFromTF"))
18  {
19  }
20 
22  {
23  }
24 
25  std::vector<std::vector<double> > TFFifoHandler::Predict(const std::vector<cvn::PixelMap const*> pixellist) const
26  {
27 
28  //
29  // loop over pixel maps to send all to TF together
30  //
31 
32  // Open the output pipe
33  std::ofstream totf;
34  totf.open(fToTF, std::ios::out);
35 
36  int nimages = pixellist.size();
37  int nviews = 2;
38 
39  // Print summary info first to pipe
40  totf << nimages << " " << nviews << " "<< pixellist[0]->NPlanePerView() << " " << pixellist[0]->NCell() << std::endl;
41 
42  // Loop over pixel maps and print them to the pipe
43  for(size_t iP = 0; iP < pixellist.size(); ++iP) {
44  // Print this pixel map to pipe
45  pixellist[iP]->ToFile(totf, iP, true);
46  }
47 
48  // Close the pipe
49  totf.close();
50 
51 
52  //
53  // Read results back from all pixel maps
54  //
55 
56  std::vector<std::vector<double>> tfoutput;
57 
58  // Open the pipe
59  std::ifstream fromtf;
60  fromtf.open(fFromTF);
61 
62  // Read results from the file
63  // Each line corresponds to a pixel map
65  while (std::getline(fromtf, line))
66  {
67  //std::cout << "Debug:" << line << std::endl;
68  std::vector<std::string> parts;
69  std::vector<double> results;
70  boost::split(parts, line, boost::is_any_of(" "));
71  for (std::string p : parts) {
72  if (!p.empty())
73  results.push_back( std::stof(p) );
74  }
75  tfoutput.emplace_back(results);
76  }
77 
78  return tfoutput;
79  }
80 }
void split(double tt, double *fr)
std::vector< std::vector< double > > Predict(const std::vector< cvn::PixelMap const * > pixellist) const
const char * p
Definition: xmltok.h:285
TFFifoHandler(fhicl::ParameterSet const &pset)
Basic constructor, takes path to model pb.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154