Public Member Functions | Private Attributes | List of all members
wavrec_tool::WaveformRecogTf Class Reference
Inheritance diagram for wavrec_tool::WaveformRecogTf:
wavrec_tool::IWaveformRecog

Public Member Functions

 WaveformRecogTf (const fhicl::ParameterSet &pset)
 
std::vector< std::vector< float > > predictWaveformType (const std::vector< std::vector< float >> &) const override
 
- Public Member Functions inherited from wavrec_tool::IWaveformRecog
virtual ~IWaveformRecog () noexcept=default
 
std::vector< boolfindROI (const std::vector< float > &adcin) const
 
std::vector< float > predROI (const std::vector< float > &adcin) const
 

Private Attributes

std::unique_ptr< tf::Graphg
 
std::string fNNetModelFilePath
 
std::vector< std::stringfNNetOutputPattern
 

Additional Inherited Members

- Protected Member Functions inherited from wavrec_tool::IWaveformRecog
std::string findFile (const char *fileName) const
 
void setupWaveRecRoiParams (const fhicl::ParameterSet &pset)
 

Detailed Description

Definition at line 11 of file WaveformRecogTf_tool.cc.

Constructor & Destructor Documentation

wavrec_tool::WaveformRecogTf::WaveformRecogTf ( const fhicl::ParameterSet pset)
explicit

Definition at line 25 of file WaveformRecogTf_tool.cc.

26  {
27  fNNetModelFilePath = pset.get<std::string>("NNetModelFile", "mymodel.pb");
29  pset.get<std::vector<std::string>>("NNetOutputPattern", {"cnn_output", "dense_3"});
30  if ((fNNetModelFilePath.length() > 3) &&
31  (fNNetModelFilePath.compare(fNNetModelFilePath.length() - 3, 3, ".pb") == 0)) {
33  if (!g) { throw art::Exception(art::errors::Unknown) << "TF model failed."; }
34  mf::LogInfo("WaveformRecogTf") << "TF model loaded.";
35  }
36  else {
37  mf::LogError("WaveformRecogTf") << "File name extension not supported.";
38  }
39 
41  }
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::string findFile(const char *fileName) const
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::vector< std::string > fNNetOutputPattern
static std::unique_ptr< Graph > create(const char *graph_file_name, const std::vector< std::string > &outputs={}, int ninputs=1, int noutputs=1)
Definition: tf_graph.h:32
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::unique_ptr< tf::Graph > g
void setupWaveRecRoiParams(const fhicl::ParameterSet &pset)

Member Function Documentation

std::vector< std::vector< float > > wavrec_tool::WaveformRecogTf::predictWaveformType ( const std::vector< std::vector< float >> &  waveforms) const
overridevirtual

Implements wavrec_tool::IWaveformRecog.

Definition at line 45 of file WaveformRecogTf_tool.cc.

46  {
47  if (waveforms.empty() || waveforms.front().empty()) {
48  return std::vector<std::vector<float>>();
49  }
50 
51  long long int samples = waveforms.size(), numtcks = waveforms.front().size();
52 
53  tensorflow::Tensor _x(tensorflow::DT_FLOAT, tensorflow::TensorShape({samples, numtcks, 1}));
54  auto input_map = _x.tensor<float, 3>();
55  for (long long int s = 0; s < samples; ++s) {
56  const auto& wvfrm = waveforms[s];
57  for (long long int t = 0; t < numtcks; ++t) {
58  input_map(s, t, 0) = wvfrm[t];
59  }
60  }
61 
62  return g->run(_x);
63  }
std::unique_ptr< tf::Graph > g
static QCString * s
Definition: config.cpp:1042

Member Data Documentation

std::string wavrec_tool::WaveformRecogTf::fNNetModelFilePath
private

Definition at line 20 of file WaveformRecogTf_tool.cc.

std::vector<std::string> wavrec_tool::WaveformRecogTf::fNNetOutputPattern
private

Definition at line 21 of file WaveformRecogTf_tool.cc.

std::unique_ptr<tf::Graph> wavrec_tool::WaveformRecogTf::g
private

Definition at line 19 of file WaveformRecogTf_tool.cc.


The documentation for this class was generated from the following file: