LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
nnet::KerasModelInterface Class Reference

#include "PointIdAlg.h"

Inheritance diagram for nnet::KerasModelInterface:
nnet::ModelInterface

Public Member Functions

 KerasModelInterface (const char *modelFileName)
 
std::vector< float > Run (std::vector< std::vector< float > > const &inp2d) override
 
virtual std::vector< std::vector< float > > Run (std::vector< std::vector< std::vector< float > > > const &inps, int samples=-1)
 

Protected Member Functions

std::string findFile (const char *fileName) const
 

Private Attributes

keras::KerasModel m
 

Detailed Description

Definition at line 64 of file PointIdAlg.h.

Constructor & Destructor Documentation

nnet::KerasModelInterface::KerasModelInterface ( const char *  modelFileName)

Definition at line 73 of file PointIdAlg.cxx.

73  :
74  m(nnet::ModelInterface::findFile(modelFileName).c_str())
75 {
76  mf::LogInfo("KerasModelInterface") << "Keras model loaded.";
77 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
keras::KerasModel m
Definition: PointIdAlg.h:72
std::string findFile(const char *fileName) const
Definition: PointIdAlg.cxx:51

Member Function Documentation

std::string nnet::ModelInterface::findFile ( const char *  fileName) const
protectedinherited

Definition at line 51 of file PointIdAlg.cxx.

References art::errors::NotFound.

Referenced by nnet::ModelInterface::ModelInterface(), and nnet::TfModelInterface::TfModelInterface().

52 {
53  std::string fname_out;
54  cet::search_path sp("FW_SEARCH_PATH");
55  if (!sp.find_file(fileName, fname_out))
56  {
57  struct stat buffer;
58  if (stat(fileName, &buffer) == 0) { fname_out = fileName; }
59  else
60  {
62  << "Could not find the model file " << fileName;
63  }
64  }
65  return fname_out;
66 }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< std::vector< float > > nnet::ModelInterface::Run ( std::vector< std::vector< std::vector< float > > > const &  inps,
int  samples = -1 
)
virtualinherited

Reimplemented in nnet::TfModelInterface.

Definition at line 35 of file PointIdAlg.cxx.

References nnet::ModelInterface::Run(), and lar::dump::vector().

36 {
37  if ((samples == 0) || inps.empty() || inps.front().empty() || inps.front().front().empty())
38  return std::vector< std::vector<float> >();
39 
40  if ((samples == -1) || (samples > (int)inps.size())) { samples = inps.size(); }
41 
42  std::vector< std::vector<float> > results;
43  for (int i = 0; i < samples; ++i)
44  {
45  results.push_back(Run(inps[i]));
46  }
47  return results;
48 }
virtual std::vector< float > Run(std::vector< std::vector< float > > const &inp2d)=0
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< float > nnet::KerasModelInterface::Run ( std::vector< std::vector< float > > const &  inp2d)
overridevirtual

Implements nnet::ModelInterface.

Definition at line 80 of file PointIdAlg.cxx.

References keras::KerasModel::compute_output(), m, and keras::DataChunk::set_data().

81 {
82  std::vector< std::vector< std::vector<float> > > inp3d;
83  inp3d.push_back(inp2d); // lots of copy, should add 2D to keras...
84 
85  keras::DataChunk *sample = new keras::DataChunk2D();
86  sample->set_data(inp3d); // and more copy...
87  std::vector<float> out = m.compute_output(sample);
88  delete sample;
89  return out;
90 }
virtual void set_data(std::vector< std::vector< std::vector< float > > > const &)
Definition: keras_model.h:47
std::vector< float > compute_output(keras::DataChunk *dc)
Definition: keras_model.cc:403
keras::KerasModel m
Definition: PointIdAlg.h:72

Member Data Documentation

keras::KerasModel nnet::KerasModelInterface::m
private

Definition at line 72 of file PointIdAlg.h.

Referenced by Run().


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