src/mlpack/tests/ann_layer_test.cpp
BOOST_AUTO_TEST_CASE(SimpleBilinearInterpolationLayerTest)
{
  // Tested output against tensorflow.image.resize_bilinear()
  arma::mat input, output, unzoomedOutput, expectedOutput;
  size_t inRowSize = 2;
  size_t inColSize = 2;
  size_t outRowSize = 5;
  size_t outColSize = 5;
  size_t depth = 1;
  input.zeros(inRowSize * inColSize * depth, 1);
  input[0] = 1.0;
  input[1] = input[2] = 2.0;
  input[3] = 3.0;
  BilinearInterpolation<> layer(inRowSize, inColSize, outRowSize, outColSize,
      depth);
  expectedOutput = arma::mat("1.0000 1.4000 1.8000 2.0000 2.0000 \
      1.4000 1.8000 2.2000 2.4000 2.4000 \
      1.8000 2.2000 2.6000 2.8000 2.8000 \
      2.0000 2.4000 2.8000 3.0000 3.0000 \
      2.0000 2.4000 2.8000 3.0000 3.0000");
  expectedOutput.reshape(25, 1);
  layer.Forward(input, output);
  CheckMatrices(output - expectedOutput, arma::zeros(output.n_rows), 1e-12);

  expectedOutput = arma::mat("1.0000 1.9000 1.9000 2.8000");
  expectedOutput.reshape(4, 1);
  layer.Backward(output, output, unzoomedOutput);
  CheckMatrices(unzoomedOutput - expectedOutput,
      arma::zeros(input.n_rows), 1e-12);
}
/*
 * Simple test for the BilinearInterpolation layer
 */
Simple test for the BilinearInterpolation layer
Simple test for the BilinearInterpolation layer
BOOST_AUTO_TEST_CASE(SimpleBilinearInterpolationLayerTest)
{
  arma::mat input, output, unzoomedOutput, expectedOutput;
  size_t inRowSize = 2;
  size_t inColSize = 2;
  size_t outRowSize = 5;
  size_t outColSize = 5;
  size_t depth = 1;
  input.zeros(inRowSize * inColSize * depth, 1);
  input[0] = 1.0;
  input[1] = input[2] = 2.0;
  input[3] = 3.0;
  BilinearInterpolation<> layer(inRowSize, inColSize, outRowSize, outColSize,
      depth);
  expectedOutput = arma::mat("1.0000 1.4000 1.8000 2.0000 2.0000 \
      1.4000 1.8000 2.2000 2.4000 2.4000 \
      1.8000 2.2000 2.6000 2.8000 2.8000 \
      2.0000 2.4000 2.8000 3.0000 3.0000 \
      2.0000 2.4000 2.8000 3.0000 3.0000");
  expectedOutput.reshape(25, 1);
  layer.Forward(input, output);
  CheckMatrices(output - expectedOutput, arma::zeros(output.n_rows), 1e-12);
  expectedOutput = arma::mat("1.0000 1.9000 1.9000 2.8000");
  expectedOutput.reshape(4, 1);
  layer.Backward(output, output, unzoomedOutput);
  CheckMatrices(unzoomedOutput - expectedOutput,
      arma::zeros(input.n_rows), 1e-12);
}
BOOST_AUTO_TEST_CASE ( SimpleBilinearInterpolationLayerTest ) { arma :: mat input , output , unzoomedOutput , expectedOutput ; size_t inRowSize = 2 ; size_t inColSize = 2 ; size_t outRowSize = 5 ; size_t outColSize = 5 ; size_t depth = 1 ; input . zeros ( inRowSize * inColSize * depth , 1 ) ; input [ 0 ] = 1.0 ; input [ 1 ] = input [ 2 ] = 2.0 ; input [ 3 ] = 3.0 ; BilinearInterpolation < > layer ( inRowSize , inColSize , outRowSize , outColSize , depth ) ; expectedOutput = arma :: mat ( " \
 \
 \
 \
 " ) ; expectedOutput . reshape ( 25 , 1 ) ; layer . Forward ( input , output ) ; CheckMatrices ( output - expectedOutput , arma :: zeros ( output . n_rows ) , 1e-12 ) ; expectedOutput = arma :: mat ( " " ) ; expectedOutput . reshape ( 4 , 1 ) ; layer . Backward ( output , output , unzoomedOutput ) ; CheckMatrices ( unzoomedOutput - expectedOutput , arma :: zeros ( input . n_rows ) , 1e-12 ) ; }
Simple test for the BilinearInterpolation layer
Simple test for the BilinearInterpolation layer
// Tested output against tensorflow.image.resize_bilinear()