Classes | Functions
keras Namespace Reference

Classes

class  DataChunk
 
class  DataChunk2D
 
class  DataChunkFlat
 
class  KerasModel
 
class  Layer
 
class  LayerActivation
 
class  LayerConv2D
 
class  LayerDense
 
class  LayerFlatten
 
class  LayerMaxPooling
 

Functions

std::vector< float > read_1d_array (std::ifstream &fin, int cols)
 
void missing_activation_impl (const std::string &act)
 
void conv_single_depth_valid (std::vector< std::vector< float > > &y, std::vector< std::vector< float > > const &im, std::vector< std::vector< float > > const &k)
 
void conv_single_depth_same (std::vector< std::vector< float > > &y, std::vector< std::vector< float > > const &im, std::vector< std::vector< float > > const &k)
 

Function Documentation

void keras::conv_single_depth_same ( std::vector< std::vector< float > > &  y,
std::vector< std::vector< float > > const &  im,
std::vector< std::vector< float > > const &  k 
)

Definition at line 273 of file keras_model.cc.

277 {
278  size_t k1_size = k.size(), k2_size = k[0].size();
279  unsigned int st_x = (k1_size - 1) >> 1;
280  unsigned int st_y = (k2_size - 1) >> 1;
281 
282  size_t max_imc = im.size() - 1;
283  size_t max_imr = im[0].size() - 1;
284 
285  for(unsigned int i = 0; i < im.size(); ++i) {
286  for(unsigned int j = 0; j < im[0].size(); ++j) {
287 
288  float sum = 0;
289  for(unsigned int k1 = 0; k1 < k1_size; ++k1) {
290  //const float * k_data = k[k1_size-k1-1].data();
291  //const float * im_data = im[i-st_x+k1].data();
292  for(unsigned int k2 = 0; k2 < k2_size; ++k2) {
293  if(i+k1 < st_x) continue;
294  if(i+k1 > max_imc+st_x) continue;
295  if(j+k2 < st_y) continue;
296  if(j+k2 > max_imr+st_y) continue;
297 
298  //sum += k_data[k2_size-k2-1] * im_data[j-st_y+k2];
299  sum += k[k1_size-k1-1][k2_size-k2-1] * im[i-st_x+k1][j-st_y+k2];
300  }
301  }
302  y[i][j] += sum;
303  }
304  }
305 }
void keras::conv_single_depth_valid ( std::vector< std::vector< float > > &  y,
std::vector< std::vector< float > > const &  im,
std::vector< std::vector< float > > const &  k 
)

Definition at line 246 of file keras_model.cc.

250 {
251  size_t k1_size = k.size(), k2_size = k[0].size();
252  unsigned int st_x = (k1_size - 1) >> 1;
253  unsigned int st_y = (k2_size - 1) >> 1;
254 
255  for(unsigned int i = st_x; i < im.size()-st_x; ++i) {
256  for(unsigned int j = st_y; j < im[0].size()-st_y; ++j) {
257 
258  float sum = 0;
259  for(unsigned int k1 = 0; k1 < k1_size; ++k1) {
260  //const float * k_data = k[k1_size-k1-1].data();
261  //const float * im_data = im[i-st_x+k1].data();
262  for(unsigned int k2 = 0; k2 < k2_size; ++k2) {
263  //sum += k_data[k2_size-k2-1] * im_data[j-st_y+k2];
264  sum += k[k1_size-k1-1][k2_size-k2-1] * im[i-st_x+k1][j-st_y+k2];
265  }
266  }
267  y[i-st_x][j-st_y] += sum;
268  }
269  }
270 }
void keras::missing_activation_impl ( const std::string act)

Definition at line 175 of file keras_model.cc.

175  {
176  cout << "Activation " << act << " not defined!" << endl;
177  cout << "Please add its implementation before use." << endl;
178  exit(1);
179 }
QTextStream & endl(QTextStream &s)
std::vector< float > keras::read_1d_array ( std::ifstream &  fin,
int  cols 
)

Definition at line 11 of file keras_model.cc.

11  {
12  vector<float> arr;
13  float tmp_float;
14  char tmp_char;
15  fin >> tmp_char; // for '['
16  for(int n = 0; n < cols; ++n) {
17  fin >> tmp_float;
18  arr.push_back(tmp_float);
19  }
20  fin >> tmp_char; // for ']'
21  return arr;
22 }
std::void_t< T > n