Beispiel #1
0
void MeanPooling<InputDataType, OutputDataType>::Forward(
    const arma::Mat<eT>&& input, arma::Mat<eT>&& output)
{
  size_t slices = input.n_elem / (inputWidth * inputHeight);
  inputTemp = arma::cube(input.memptr(), inputWidth, inputHeight, slices);

  if (floor)
  {
    outputWidth = std::floor((inputWidth - (double) kW) / (double) dW + 1);
    outputHeight = std::floor((inputHeight - (double) kH) / (double) dH + 1);

    offset = 0;
  }
  else
  {
    outputWidth = std::ceil((inputWidth - (double) kW) / (double) dW + 1);
    outputHeight = std::ceil((inputHeight - (double) kH) / (double) dH + 1);

    offset = 1;
  }

  outputTemp = arma::zeros<arma::Cube<eT> >(outputWidth, outputHeight,
      slices);

  for (size_t s = 0; s < inputTemp.n_slices; s++)
    Pooling(inputTemp.slice(s), outputTemp.slice(s));

  output = arma::Mat<eT>(outputTemp.memptr(), outputTemp.n_elem, 1);

  outputWidth = outputTemp.n_rows;
  outputHeight = outputTemp.n_cols;
  outSize = slices;
}
Beispiel #2
0
  void Forward(const arma::Cube<eT>& input, arma::Cube<eT>& output)
  {
    output = arma::zeros<arma::Cube<eT> >(input.n_rows / kSize,
                            input.n_cols / kSize, input.n_slices);

    for (size_t s = 0; s < input.n_slices; s++)
      Pooling(input.slice(s), output.slice(s));
  }
 void FeedForward(const arma::Cube<eT>& input)
 {
   for (size_t s = 0; s < input.n_slices; s++)
     Pooling(input.slice(s), outputLayer.InputActivation().slice(s));
 }
 void FeedForward(const arma::Mat<eT>& input)
 {
   Pooling(input, outputLayer.InputActivation());
 }
Beispiel #5
0
 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output)
 {
   Pooling(input, output);
 }
Beispiel #6
0
void Glimpse<InputDataType, OutputDataType>::Forward(
    const arma::Mat<eT>&& input, arma::Mat<eT>&& output)
{
  inputTemp = arma::cube(input.colptr(0), inputWidth, inputHeight, inSize);
  outputTemp = arma::Cube<eT>(size, size, depth * inputTemp.n_slices);

  location = input.submat(0, 1, 1, 1);

  if (!deterministic)
  {
    locationParameter.push_back(location);
  }

  inputDepth = inputTemp.n_slices / inSize;

  for (size_t inputIdx = 0; inputIdx < inSize; inputIdx++)
  {
    for (size_t depthIdx = 0, glimpseSize = size;
        depthIdx < depth; depthIdx++, glimpseSize *= scale)
    {
      size_t padSize = std::floor((glimpseSize - 1) / 2);

      arma::Cube<eT> inputPadded = arma::zeros<arma::Cube<eT> >(
          inputTemp.n_rows + padSize * 2, inputTemp.n_cols + padSize * 2,
          inputTemp.n_slices / inSize);

      inputPadded.tube(padSize, padSize, padSize + inputTemp.n_rows - 1,
          padSize + inputTemp.n_cols - 1) = inputTemp.subcube(0, 0,
          inputIdx * inputDepth, inputTemp.n_rows - 1, inputTemp.n_cols - 1,
          (inputIdx + 1) * inputDepth - 1);

      size_t h = inputPadded.n_rows - glimpseSize;
      size_t w = inputPadded.n_cols - glimpseSize;

      size_t x = std::min(h, (size_t) std::max(0.0,
          (location(0, inputIdx) + 1) / 2.0 * h));
      size_t y = std::min(w, (size_t) std::max(0.0,
          (location(1, inputIdx) + 1) / 2.0 * w));

      if (depthIdx == 0)
      {
        for (size_t j = (inputIdx + depthIdx), paddedSlice = 0;
            j < outputTemp.n_slices; j += (inSize * depth), paddedSlice++)
        {
          outputTemp.slice(j) = inputPadded.subcube(x, y,
              paddedSlice, x + glimpseSize - 1, y + glimpseSize - 1,
              paddedSlice);
        }
      }
      else
      {
        for (size_t j = (inputIdx + depthIdx * (depth - 1)), paddedSlice = 0;
            j < outputTemp.n_slices; j += (inSize * depth), paddedSlice++)
        {
          arma::Mat<eT> poolingInput = inputPadded.subcube(x, y,
              paddedSlice, x + glimpseSize - 1, y + glimpseSize - 1,
              paddedSlice);

          if (scale == 2)
          {
            Pooling(glimpseSize / size, poolingInput, outputTemp.slice(j));
          }
          else
          {
            ReSampling(poolingInput, outputTemp.slice(j));
          }
        }
      }
    }
  }

  for (size_t i = 0; i < outputTemp.n_slices; ++i)
  {
    outputTemp.slice(i) = arma::trans(outputTemp.slice(i));
  }

  output = arma::Mat<eT>(outputTemp.memptr(), outputTemp.n_elem, 1);

  outputWidth = outputTemp.n_rows;
  outputHeight = outputTemp.n_cols;
}