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

#include "keras_model.h"

Inheritance diagram for keras::LayerActivation:
keras::Layer

Public Member Functions

 LayerActivation ()
 
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::string m_activation_type
 
std::string m_name
 

Detailed Description

Definition at line 164 of file keras_model.h.

Constructor & Destructor Documentation

keras::LayerActivation::LayerActivation ( )
inline

Definition at line 166 of file keras_model.h.

References fin.

166 : Layer("Activation") {}
Layer(std::string name)
Definition: keras_model.h:124

Member Function Documentation

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

Implements keras::Layer.

Definition at line 184 of file keras_model.cc.

References keras::DataChunk::get_1d(), keras::DataChunk::get_3d(), keras::DataChunk::get_data_dim(), keras::missing_activation_impl(), keras::DataChunk::set_data(), and y.

184  {
185 
186  if (dc->get_data_dim() == 3) {
187  vector<vector<vector<float> > > y = dc->get_3d();
188  if(m_activation_type == "relu") {
189  for(unsigned int i = 0; i < y.size(); ++i) {
190  for(unsigned int j = 0; j < y[0].size(); ++j) {
191  for(unsigned int k = 0; k < y[0][0].size(); ++k) {
192  if(y[i][j][k] < 0) y[i][j][k] = 0;
193  }
194  }
195  }
196  } else if(m_activation_type == "tanh") {
197  for(unsigned int i = 0; i < y.size(); ++i) {
198  for(unsigned int j = 0; j < y[0].size(); ++j) {
199  for(unsigned int k = 0; k < y[0][0].size(); ++k) {
200  y[i][j][k] = tanh(y[i][j][k]);
201  }
202  }
203  }
204  } else {
206  }
207 
209  out->set_data(y);
210  return out;
211 
212  } else if (dc->get_data_dim() == 1) { // flat data, use 1D
213  vector<float> y = dc->get_1d();
214  if(m_activation_type == "relu") {
215  for(unsigned int k = 0; k < y.size(); ++k) {
216  if(y[k] < 0) y[k] = 0;
217  }
218  } else if(m_activation_type == "softmax") {
219  float sum = 0.0;
220  for(unsigned int k = 0; k < y.size(); ++k) {
221  y[k] = exp(y[k]);
222  sum += y[k];
223  }
224  for(unsigned int k = 0; k < y.size(); ++k) {
225  y[k] /= sum;
226  }
227  } else if(m_activation_type == "tanh") {
228  for(unsigned int k = 0; k < y.size(); ++k) {
229  y[k] = tanh(y[k]);
230  }
231  } else if(m_activation_type == "sigmoid") {
232  for(unsigned int k = 0; k < y.size(); ++k) {
233  y[k] = 1.0F / (1.0F + exp(-y[k]));
234  }
235  } else {
237  }
238 
239  keras::DataChunk *out = new DataChunkFlat();
240  out->set_data(y);
241  return out;
242 
243  } else { throw "data dim not supported"; }
244 
245  return dc;
246 }
Float_t y
Definition: compare.C:6
virtual void set_data(std::vector< std::vector< std::vector< float > > > const &)
Definition: keras_model.h:47
virtual std::vector< std::vector< std::vector< float > > > const & get_3d() const
Definition: keras_model.h:46
virtual size_t get_data_dim(void) const
Definition: keras_model.h:44
std::string m_activation_type
Definition: keras_model.h:174
void missing_activation_impl(const std::string &act)
Definition: keras_model.cc:178
virtual std::vector< float > const & get_1d() const
Definition: keras_model.h:45
virtual unsigned int keras::LayerActivation::get_input_cols ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 171 of file keras_model.h.

171 { return 0; } // same as for rows
virtual unsigned int keras::LayerActivation::get_input_rows ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 170 of file keras_model.h.

170 { return 0; } // look for the value in the preceding layer
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::LayerActivation::get_output_units ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 172 of file keras_model.h.

172 { return 0; }
void keras::LayerActivation::load_weights ( std::ifstream &  fin)
virtual

Implements keras::Layer.

Definition at line 84 of file keras_model.cc.

84  {
86  cout << "Activation type " << m_activation_type << endl;
87 }
std::string m_activation_type
Definition: keras_model.h:174
TString fin
Definition: Style.C:24

Member Data Documentation

std::string keras::LayerActivation::m_activation_type

Definition at line 174 of file keras_model.h.

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

Definition at line 132 of file keras_model.h.


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