Public Member Functions | Public Attributes | List of all members
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
 
- Public Member Functions inherited from keras::Layer
 Layer (std::string name)
 
virtual ~Layer ()
 
std::string get_name ()
 

Public Attributes

std::string m_activation_type
 
- Public Attributes inherited from keras::Layer
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.

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 181 of file keras_model.cc.

181  {
182 
183  if (dc->get_data_dim() == 3) {
184  vector<vector<vector<float> > > y = dc->get_3d();
185  if(m_activation_type == "relu") {
186  for(unsigned int i = 0; i < y.size(); ++i) {
187  for(unsigned int j = 0; j < y[0].size(); ++j) {
188  for(unsigned int k = 0; k < y[0][0].size(); ++k) {
189  if(y[i][j][k] < 0) y[i][j][k] = 0;
190  }
191  }
192  }
193  } else if(m_activation_type == "tanh") {
194  for(unsigned int i = 0; i < y.size(); ++i) {
195  for(unsigned int j = 0; j < y[0].size(); ++j) {
196  for(unsigned int k = 0; k < y[0][0].size(); ++k) {
197  y[i][j][k] = tanh(y[i][j][k]);
198  }
199  }
200  }
201  } else {
203  }
204 
206  out->set_data(y);
207  return out;
208 
209  } else if (dc->get_data_dim() == 1) { // flat data, use 1D
210  vector<float> y = dc->get_1d();
211  if(m_activation_type == "relu") {
212  for(unsigned int k = 0; k < y.size(); ++k) {
213  if(y[k] < 0) y[k] = 0;
214  }
215  } else if(m_activation_type == "softmax") {
216  float sum = 0.0;
217  for(unsigned int k = 0; k < y.size(); ++k) {
218  y[k] = exp(y[k]);
219  sum += y[k];
220  }
221  for(unsigned int k = 0; k < y.size(); ++k) {
222  y[k] /= sum;
223  }
224  } else if(m_activation_type == "tanh") {
225  for(unsigned int k = 0; k < y.size(); ++k) {
226  y[k] = tanh(y[k]);
227  }
228  } else if(m_activation_type == "sigmoid") {
229  for(unsigned int k = 0; k < y.size(); ++k) {
230  y[k] = 1.0F / (1.0F + exp(-y[k]));
231  }
232  } else {
234  }
235 
236  keras::DataChunk *out = new DataChunkFlat();
237  out->set_data(y);
238  return out;
239 
240  } else { throw "data dim not supported"; }
241 
242  return dc;
243 }
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:175
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
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 81 of file keras_model.cc.

81  {
82  fin >> m_activation_type;
83  cout << "Activation type " << m_activation_type << endl;
84 }
std::string m_activation_type
Definition: keras_model.h:174
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::string keras::LayerActivation::m_activation_type

Definition at line 174 of file keras_model.h.


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