RegCNN_TF_Graph.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////////////////////////
2 //// Class: RegCNNGraph
3 //// Authors: Ilsoo Seong - iseong@uci.edu
4 //// Authors: R.Sulej (Robert.Sulej@cern.ch), from DUNE, FNAL/NCBJ, Sept. 2017
5 /// P.Plonski, from DUNE, WUT, Sept. 2017
6 ////
7 //// Iterface to run Tensorflow graph saved to a file. First attempts, almost functional.
8 //// modified from tf_graph.h
9 ////
10 ////////////////////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef RegCNNGraph_h
13 #define RegCNNGraph_h
14 
15 #include <memory>
16 #include <vector>
17 #include <string>
18 
19 namespace tensorflow
20 {
21  class Session;
22  class Tensor;
23 }
24 
25 namespace tf
26 {
27 
29 {
30 public:
31  static std::unique_ptr<RegCNNGraph> create(const char* graph_file_name, const unsigned int &ninputs, const std::vector<std::string> & outputs = {})
32  {
33  bool success;
34  std::unique_ptr<RegCNNGraph> ptr(new RegCNNGraph(graph_file_name, ninputs, outputs, success));
35  if (success) { return ptr; }
36  else { return nullptr; }
37  }
38 
39  ~RegCNNGraph();
40 
41  std::vector<float> run(const std::vector< std::vector<float> > & x);
42 
43  // process vector of 3D inputs, return vector of 1D outputs; use all inputs
44  // if samples = -1, or only the specified number of first samples
45  std::vector< std::vector<float> > run(
46  const std::vector< std::vector< std::vector< std::vector<float> > > > & x,
47  long long int samples = -1);
48  std::vector< std::vector<float> > run(
49  const std::vector< std::vector< std::vector< std::vector<float> > > > & x,
50  const unsigned int& ninputs,
51  long long int samples = -1);
52  std::vector< std::vector<float> > run(
53  const std::vector< std::vector< std::vector< std::vector<float> > > > & x,
54  const std::vector<float> cm, const unsigned int& ninputs,
55  long long int samples = -1);
56 
57  std::vector< std::vector< float > > run(const tensorflow::Tensor & x);
58  std::vector< std::vector< float > > run(const std::vector< tensorflow::Tensor >& x);
59 
60 private:
61  /// Not-throwing constructor.
62  RegCNNGraph(const char* graph_file_name, const unsigned int& ninputs, const std::vector<std::string> & outputs, bool & success);
63 
64  tensorflow::Session* fSession;
65  std::vector<std::string> fInputNames;
66  std::vector< std::string > fOutputNames;
67 };
68 
69 } // namespace tf
70 
71 #endif
static constexpr double cm
Definition: Units.h:68
struct vector vector
Definition: tf_graph.h:23
std::vector< std::string > fInputNames
std::vector< std::string > fOutputNames
static std::unique_ptr< RegCNNGraph > create(const char *graph_file_name, const unsigned int &ninputs, const std::vector< std::string > &outputs={})
list x
Definition: train.py:276
tensorflow::Session * fSession