Public Member Functions | Private Member Functions | Private Attributes | List of all members
keras::KerasModel Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-21/ExoticsTriggers/KerasModel.h"

Public Member Functions

 KerasModel (const std::string &input_fname)
 
 ~KerasModel ()
 
std::vector< float > compute_output (keras::DataChunk *dc)
 
unsigned int get_input_rows () const
 
unsigned int get_input_cols () const
 
int get_output_length () const
 
 KerasModel (const std::string &input_fname, bool verbose)
 
 ~KerasModel ()
 
std::vector< float > compute_output (keras::DataChunk *dc)
 
unsigned int get_input_rows () const
 
unsigned int get_input_cols () const
 
int get_output_length () const
 

Private Member Functions

void load_weights (const std::string &input_fname)
 
void load_weights (const std::string &input_fname)
 

Private Attributes

int m_layers_cnt
 
std::vector< Layer * > m_layers
 
bool m_verbose
 

Detailed Description

Definition at line 201 of file KerasModel.h.

Constructor & Destructor Documentation

keras::KerasModel::KerasModel ( const std::string input_fname)
keras::KerasModel::~KerasModel ( )

Definition at line 411 of file KerasModel.cxx.

References MECModelEnuComparisons::i, and makeTrainCVSamples::int.

Referenced by load_weights().

411  {
412  for(int i = 0; i < (int)m_layers.size(); ++i) {
413  delete m_layers[i];
414  }
415 }
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
keras::KerasModel::KerasModel ( const std::string input_fname,
bool  verbose 
)
keras::KerasModel::~KerasModel ( )

Member Function Documentation

std::vector<float> keras::KerasModel::compute_output ( keras::DataChunk dc)
std::vector< float > keras::KerasModel::compute_output ( keras::DataChunk dc)

Definition at line 354 of file KerasModel.cxx.

References om::cout, allTimeWatchdog::endl, fin, keras::DataChunk::get_1d(), makeTrainCVSamples::int, submit_hadd::l, CLHEP::L, elec2geo::layer, keras::Layer::load_weights(), load_weights(), confusionMatrixTree::out, and keras::DataChunk::show_values().

Referenced by ncid::NCNNKerasVal::analyze(), novaddt::NNFastMMTrigger::filter(), keras::missing_activation_impl(), and ncid::NCNNKeras::produce().

354  {
355 
356  keras::DataChunk *inp = dc;
357  keras::DataChunk *out = 0;
358  for(int l = 0; l < (int)m_layers.size(); ++l) {
359  out = m_layers[l]->compute_output(inp);
360 
361  if(inp != dc) delete inp;
362  //delete inp;
363  inp = 0L;
364  inp = out;
365  }
366 
367  out->show_values();
368 
369  std::vector<float> flat_out = out->get_1d();
370  delete out;
371 
372  return flat_out;
373 }
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
virtual void show_values()=0
static constexpr double L
virtual std::vector< float > const & get_1d() const
Definition: KerasModel.h:36
unsigned int keras::KerasModel::get_input_cols ( ) const
inline

Definition at line 206 of file KerasModel.h.

References string.

206 { return m_layers.front()->get_input_cols(); }
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
unsigned int keras::KerasModel::get_input_cols ( ) const
inline

Definition at line 208 of file KerasModel.h.

References string.

208 { return m_layers.front()->get_input_cols(); }
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
unsigned int keras::KerasModel::get_input_rows ( ) const
inline

Definition at line 205 of file KerasModel.h.

205 { return m_layers.front()->get_input_rows(); }
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
unsigned int keras::KerasModel::get_input_rows ( ) const
inline

Definition at line 207 of file KerasModel.h.

207 { return m_layers.front()->get_input_rows(); }
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
int keras::KerasModel::get_output_length ( ) const
int keras::KerasModel::get_output_length ( ) const

Definition at line 417 of file KerasModel.cxx.

References MECModelEnuComparisons::i.

Referenced by load_weights().

418 {
419  int i = m_layers.size() - 1;
420  while ((i > 0) && (m_layers[i]->get_output_units() == 0)) --i;
421  return m_layers[i]->get_output_units();
422 }
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
void keras::KerasModel::load_weights ( const std::string input_fname)
private
void keras::KerasModel::load_weights ( const std::string input_fname)
private

Definition at line 416 of file KerasModel.cxx.

References om::cout, allTimeWatchdog::endl, fin, get_output_length(), MECModelEnuComparisons::i, makeTrainCVSamples::int, submit_hadd::l, CLHEP::L, elec2geo::layer, keras::Layer::load_weights(), m_layers, m_layers_cnt, m_verbose, string, and ~KerasModel().

Referenced by compute_output(), and KerasModel().

417 {
418  if(m_verbose) std::cout << "Reading model from " << input_fname << std::endl;
419  std::ifstream fin(input_fname.c_str());
420  std::string layer_type = "";
421  std::string tmp_str = "";
422  int tmp_int = 0;
423 
424  fin >> tmp_str >> m_layers_cnt;
425  if(m_verbose) std::cout << "Layers " << m_layers_cnt << std::endl;
426 
427  for(int layer = 0; layer < m_layers_cnt; ++layer) { // iterate over layers
428  fin >> tmp_str >> tmp_int >> layer_type;
429  if(m_verbose) std::cout << "Layer " << tmp_int << " " << layer_type << std::endl;
430 
431  Layer *l = 0L;
432  if(layer_type == "Convolution2D") {
433  l = new LayerConv2D();
434  }
435  else if(layer_type == "Activation") {
436  l = new LayerActivation();
437  }
438  else if(layer_type == "MaxPooling2D") {
439  l = new LayerMaxPooling();
440  }
441  else if(layer_type == "Flatten") {
442  l = new LayerFlatten();
443  }
444  else if(layer_type == "Dense") {
445  l = new LayerDense();
446  }
447  else if(layer_type == "Dropout") {
448  continue; // we dont need dropout layer in prediciton mode
449  }
450  if(l == 0L) {
451  std::cout << "Layer is empty, maybe it is not defined? Cannot define network." << std::endl;
452  return;
453  }
454  l->load_weights(fin);
455  m_layers.push_back(l);
456  }
457 
458  fin.close();
459 }
TString fin
Definition: Style.C:24
std::vector< Layer * > m_layers
Definition: KerasModel.h:215
static constexpr double L
OStream cout
Definition: OStream.cxx:6
enum BeamMode string

Member Data Documentation

std::vector< Layer * > keras::KerasModel::m_layers
private

Definition at line 215 of file KerasModel.h.

Referenced by load_weights(), and keras::missing_activation_impl().

int keras::KerasModel::m_layers_cnt
private

Definition at line 214 of file KerasModel.h.

Referenced by load_weights().

bool keras::KerasModel::m_verbose
private

Definition at line 214 of file KerasModel.h.

Referenced by load_weights().


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