src/cnn.cpp
ConvolutionalLayer::ConvolutionalLayer(size_t nInputs, size_t nOutputs, int h, int w)
  : MIMOFeatureTransform(nInputs, nOutputs) {
  if (w == -1)
    w = h;

  assert(nInputs > 0 && nOutputs > 0 && h > 0 && w > 0);

  printf("Initializing %lu x %lu kernels of size %d x %d\n", nInputs, nOutputs, h, w);

  size_t fan_in = nInputs * w * h,
         fan_out = nOutputs * w * h;
  float coeff = 2 * sqrt(6.0f / (fan_in + fan_out));

  _kernels.resize(nInputs);
  for (size_t i=0; i<nInputs; ++i) {
    _kernels[i].resize(nOutputs);
    for (size_t j=0; j<nOutputs; ++j)
      _kernels[i][j] = (rand(h, w) - 0.5f) * coeff;
  }

  _bias.resize(nOutputs);
  for (size_t j=0; j<nOutputs; ++j)
    _bias[j] = 0;
}
/*! 
 * Implementation of ConvolutionalLayer goes here.
 */
Implementation of ConvolutionalLayer goes here.
Implementation of ConvolutionalLayer goes here .
ConvolutionalLayer::ConvolutionalLayer(size_t nInputs, size_t nOutputs, int h, int w)
  : MIMOFeatureTransform(nInputs, nOutputs) {
  if (w == -1)
    w = h;
  assert(nInputs > 0 && nOutputs > 0 && h > 0 && w > 0);
  printf("Initializing %lu x %lu kernels of size %d x %d\n", nInputs, nOutputs, h, w);
  size_t fan_in = nInputs * w * h,
         fan_out = nOutputs * w * h;
  float coeff = 2 * sqrt(6.0f / (fan_in + fan_out));
  _kernels.resize(nInputs);
  for (size_t i=0; i<nInputs; ++i) {
    _kernels[i].resize(nOutputs);
    for (size_t j=0; j<nOutputs; ++j)
      _kernels[i][j] = (rand(h, w) - 0.5f) * coeff;
  }
  _bias.resize(nOutputs);
  for (size_t j=0; j<nOutputs; ++j)
    _bias[j] = 0;
}
ConvolutionalLayer :: ConvolutionalLayer ( size_t nInputs , size_t nOutputs , int h , int w ) : MIMOFeatureTransform ( nInputs , nOutputs ) { if ( w == -1 ) w = h ; assert ( nInputs > 0 && nOutputs > 0 && h > 0 && w > 0 ) ; printf ( " \n " , nInputs , nOutputs , h , w ) ; size_t fan_in = nInputs * w * h , fan_out = nOutputs * w * h ; float coeff = 2 * sqrt ( 6.0f / ( fan_in + fan_out ) ) ; _kernels . resize ( nInputs ) ; for ( size_t i = 0 ; i < nInputs ; ++ i ) { _kernels [ i ] . resize ( nOutputs ) ; for ( size_t j = 0 ; j < nOutputs ; ++ j ) _kernels [ i ] [ j ] = ( rand ( h , w ) - 0.5f ) * coeff ; } _bias . resize ( nOutputs ) ; for ( size_t j = 0 ; j < nOutputs ; ++ j ) _bias [ j ] = 0 ; }
Implementation of ConvolutionalLayer goes here.
Implementation of ConvolutionalLayer goes here .