LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
keras::LayerDense Class Reference

#include "keras_model.h"

Inheritance diagram for keras::LayerDense:
keras::Layer

Public Member Functions

 LayerDense ()
 
void load_weights (std::ifstream &fin)
 
keras::DataChunkcompute_output (keras::DataChunk *)
 
virtual unsigned int get_input_rows () const
 
virtual unsigned int get_input_cols () const
 
virtual unsigned int get_output_units () const
 
std::string get_name ()
 

Public Attributes

std::vector< std::vector< float > > m_weights
 
std::vector< float > m_bias
 
int m_input_cnt
 
int m_neurons
 
std::string m_name
 

Detailed Description

Definition at line 197 of file keras_model.h.

Constructor & Destructor Documentation

keras::LayerDense::LayerDense ( )
inline

Definition at line 199 of file keras_model.h.

References fin.

199 : Layer("Dense") {}
Layer(std::string name)
Definition: keras_model.h:124

Member Function Documentation

keras::DataChunk * keras::LayerDense::compute_output ( keras::DataChunk dc)
virtual

Implements keras::Layer.

Definition at line 366 of file keras_model.cc.

References keras::DataChunk::get_1d(), keras::DataChunkFlat::get_1d_rw(), and w.

366  {
367  //cout << "weights: input size " << m_weights.size() << endl;
368  //cout << "weights: neurons size " << m_weights[0].size() << endl;
369  //cout << "bias " << m_bias.size() << endl;
370  size_t size = m_weights[0].size();
371  size_t size8 = size >> 3;
372 
373  keras::DataChunkFlat *out = new DataChunkFlat(size, 0);
374  float * y_ret = out->get_1d_rw().data();
375 
376  auto const & im = dc->get_1d();
377 
378  for (size_t j = 0; j < m_weights.size(); ++j) { // iter over input
379  const float * w = m_weights[j].data();
380  float p = im[j];
381  size_t k = 0;
382  for (size_t i = 0; i < size8; ++i) { // iter over neurons
383  y_ret[k] += w[k] * p; // vectorize if you can
384  y_ret[k+1] += w[k+1] * p;
385  y_ret[k+2] += w[k+2] * p;
386  y_ret[k+3] += w[k+3] * p;
387  y_ret[k+4] += w[k+4] * p;
388  y_ret[k+5] += w[k+5] * p;
389  y_ret[k+6] += w[k+6] * p;
390  y_ret[k+7] += w[k+7] * p;
391  k += 8;
392  }
393  while (k < size) { y_ret[k] += w[k] * p; ++k; }
394  }
395  for (size_t i = 0; i < size; ++i) { // add biases
396  y_ret[i] += m_bias[i];
397  }
398 
399  return out;
400 }
std::vector< std::vector< float > > m_weights
Definition: keras_model.h:203
std::vector< float > & get_1d_rw()
Definition: keras_model.h:102
std::vector< float > m_bias
Definition: keras_model.h:204
Float_t w
Definition: plot.C:23
virtual std::vector< float > const & get_1d() const
Definition: keras_model.h:45
virtual unsigned int keras::LayerDense::get_input_cols ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 207 of file keras_model.h.

207 { return m_input_cnt; }
virtual unsigned int keras::LayerDense::get_input_rows ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 206 of file keras_model.h.

206 { return 1; } // flat, just one row
std::string keras::Layer::get_name ( )
inlineinherited

Definition at line 131 of file keras_model.h.

131 { return m_name; }
std::string m_name
Definition: keras_model.h:132
virtual unsigned int keras::LayerDense::get_output_units ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 208 of file keras_model.h.

208 { return m_neurons; }
void keras::LayerDense::load_weights ( std::ifstream &  fin)
virtual

Implements keras::Layer.

Definition at line 94 of file keras_model.cc.

References n.

94  {
96  float tmp_float;
97  char tmp_char = ' ';
98  for(int i = 0; i < m_input_cnt; ++i) {
99  vector<float> tmp_n;
100  fin >> tmp_char; // for '['
101  for(int n = 0; n < m_neurons; ++n) {
102  fin >> tmp_float;
103  tmp_n.push_back(tmp_float);
104  }
105  fin >> tmp_char; // for ']'
106  m_weights.push_back(tmp_n);
107  }
108  cout << "weights " << m_weights.size() << endl;
109  fin >> tmp_char; // for '['
110  for(int n = 0; n < m_neurons; ++n) {
111  fin >> tmp_float;
112  m_bias.push_back(tmp_float);
113  }
114  fin >> tmp_char; // for ']'
115  cout << "bias " << m_bias.size() << endl;
116 
117 }
std::vector< std::vector< float > > m_weights
Definition: keras_model.h:203
TString fin
Definition: Style.C:24
std::vector< float > m_bias
Definition: keras_model.h:204
Char_t n[5]

Member Data Documentation

std::vector<float> keras::LayerDense::m_bias

Definition at line 204 of file keras_model.h.

int keras::LayerDense::m_input_cnt

Definition at line 210 of file keras_model.h.

std::string keras::Layer::m_name
inherited

Definition at line 132 of file keras_model.h.

int keras::LayerDense::m_neurons

Definition at line 211 of file keras_model.h.

std::vector<std::vector<float> > keras::LayerDense::m_weights

Definition at line 203 of file keras_model.h.


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