LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 176 of file keras_model.h.

Constructor & Destructor Documentation

keras::LayerActivation::LayerActivation ( )
inline

Definition at line 178 of file keras_model.h.

References fin.

178 : Layer("Activation") {}
Layer(std::string name)
Definition: keras_model.h:133

Member Function Documentation

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

Implements keras::Layer.

Definition at line 190 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(), sum, and y.

191 {
192 
193  if (dc->get_data_dim() == 3) {
194  vector<vector<vector<float>>> y = dc->get_3d();
195  if (m_activation_type == "relu") {
196  for (unsigned int i = 0; i < y.size(); ++i) {
197  for (unsigned int j = 0; j < y[0].size(); ++j) {
198  for (unsigned int k = 0; k < y[0][0].size(); ++k) {
199  if (y[i][j][k] < 0) y[i][j][k] = 0;
200  }
201  }
202  }
203  }
204  else if (m_activation_type == "tanh") {
205  for (unsigned int i = 0; i < y.size(); ++i) {
206  for (unsigned int j = 0; j < y[0].size(); ++j) {
207  for (unsigned int k = 0; k < y[0][0].size(); ++k) {
208  y[i][j][k] = tanh(y[i][j][k]);
209  }
210  }
211  }
212  }
213  else {
215  }
216 
218  out->set_data(y);
219  return out;
220  }
221  else if (dc->get_data_dim() == 1) { // flat data, use 1D
222  vector<float> y = dc->get_1d();
223  if (m_activation_type == "relu") {
224  for (unsigned int k = 0; k < y.size(); ++k) {
225  if (y[k] < 0) y[k] = 0;
226  }
227  }
228  else if (m_activation_type == "softmax") {
229  float sum = 0.0;
230  for (unsigned int k = 0; k < y.size(); ++k) {
231  y[k] = exp(y[k]);
232  sum += y[k];
233  }
234  for (unsigned int k = 0; k < y.size(); ++k) {
235  y[k] /= sum;
236  }
237  }
238  else if (m_activation_type == "tanh") {
239  for (unsigned int k = 0; k < y.size(); ++k) {
240  y[k] = tanh(y[k]);
241  }
242  }
243  else if (m_activation_type == "sigmoid") {
244  for (unsigned int k = 0; k < y.size(); ++k) {
245  y[k] = 1.0F / (1.0F + exp(-y[k]));
246  }
247  }
248  else {
250  }
251 
252  keras::DataChunk* out = new DataChunkFlat();
253  out->set_data(y);
254  return out;
255  }
256  else {
257  throw "data dim not supported";
258  }
259 
260  return dc;
261 }
Float_t y
Definition: compare.C:6
virtual void set_data(std::vector< std::vector< std::vector< float >>> const &)
Definition: keras_model.h:53
virtual std::vector< std::vector< std::vector< float > > > const & get_3d() const
Definition: keras_model.h:49
virtual size_t get_data_dim(void) const
Definition: keras_model.h:47
std::string m_activation_type
Definition: keras_model.h:189
void missing_activation_impl(const std::string &act)
Definition: keras_model.cc:183
Double_t sum
Definition: plot.C:31
virtual std::vector< float > const & get_1d() const
Definition: keras_model.h:48
virtual unsigned int keras::LayerActivation::get_input_cols ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 186 of file keras_model.h.

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

Implements keras::Layer.

Definition at line 182 of file keras_model.h.

183  {
184  return 0;
185  } // look for the value in the preceding layer
std::string keras::Layer::get_name ( )
inlineinherited

Definition at line 140 of file keras_model.h.

140 { return m_name; }
std::string m_name
Definition: keras_model.h:141
virtual unsigned int keras::LayerActivation::get_output_units ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 187 of file keras_model.h.

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

Implements keras::Layer.

Definition at line 86 of file keras_model.cc.

87 {
89  cout << "Activation type " << m_activation_type << endl;
90 }
TString fin
Definition: Style.C:24
std::string m_activation_type
Definition: keras_model.h:189

Member Data Documentation

std::string keras::LayerActivation::m_activation_type

Definition at line 189 of file keras_model.h.

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

Definition at line 141 of file keras_model.h.


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