25 #ifndef CONVOLUTIONLAYERTESTS_HPP_
26 #define CONVOLUTIONLAYERTESTS_HPP_
28 #include <gtest/gtest.h>
31 #define private public
32 #define protected public
36 namespace mic {
namespace neural_nets {
namespace unit_tests {
49 x = MAKE_MATRIX_PTR(
double, 8, 1);
51 desired_y = MAKE_MATRIX_PTR(
double, 8, 1);
53 dy = MAKE_MATRIX_PTR(
double, 8, 1);
55 target_y = MAKE_MATRIX_PTR(
double, 8, 1);
77 (*desired_y) << 8, 10, 12, 14, 5, 9 ,13, 17;
80 (*desired_dx) << 12, 15, 18, 21, 4, 7, 10, 13;
81 (*target_y) << 13, 13, 20, 10, 3, 2, 12, 15;
83 (*desired_dW) << 14, 126, 38, 38;
84 (*desired_db) << 6, 22;
95 mic::types::MatrixPtr<double>
x;
101 mic::types::MatrixPtr<double>
dy;
129 x = MAKE_MATRIX_PTR(
float, 18, 1);
131 desired_y = MAKE_MATRIX_PTR(
float, 12, 1);
138 (*
layer.
p[
"W0x0"]) << 0, 1, 1, 0;
139 (*
layer.
p[
"W0x1"]) << 0, -1, -1, 0;
141 (*
layer.
p[
"W1x0"]) << -1, 0, 0, 1;
142 (*
layer.
p[
"W1x1"]) << 1, 0, 0, -1;
144 (*
layer.
p[
"W2x0"]) << 0, 0, 1, 1;
145 (*
layer.
p[
"W2x1"]) << 0, 0, -1, -1;
148 (*
layer.
p[
"b"]) << 1, 0, -1;
150 (*x) << 1, 4, 7, 2, 5, 8, 3, 6, 9, 9, 6, 3, 8, 5, 2, 7, 4, 1;
151 (*desired_y) << -7, 5, -3, 9, 8, 8, 8, 8, -7, 5, -3, 9;
160 mic::types::MatrixPtr<float>
x;
178 x = MAKE_MATRIX_PTR(
float, 16, 1);
180 desired_y = MAKE_MATRIX_PTR(
float, 4, 1);
182 dy = MAKE_MATRIX_PTR(
float, 4, 1);
194 (*
layer.
p[
"W0x0"]) << 0, 1, 2, 3;
200 (*desired_y) << 24, 36, 72, 84;
203 (*desired_dx) << 0, 0, 0, 1, 0, 0, 2, 3, 0, 2, 0, 3, 4, 6, 6, 9;
205 (*desired_dW) << 48, 54, 72, 78;
214 mic::types::MatrixPtr<float>
x;
220 mic::types::MatrixPtr<float>
dy;
244 x = MAKE_MATRIX_PTR(
double, 16, 1);
246 desired_y = MAKE_MATRIX_PTR(
double, 12, 1);
248 dy = MAKE_MATRIX_PTR(
double, 12, 1);
267 (*
layer.
p[
"b"]) << -1, 0, 1;
270 (*desired_y) << -1, -1, -1, -1, 0, 3, 12,15, 1, 7, 25, 31;
273 (*desired_dx) << 20, 0, 0, 23, 0,0,0,0,0,0,0,0, 26, 0,0, 29;
276 (*desired_dW) << 72, 192, 312;
277 (*desired_db) << 6, 22, 38;
288 mic::types::MatrixPtr<double>
x;
294 mic::types::MatrixPtr<double>
dy;
320 x = MAKE_MATRIX_PTR(
float, 25, 1);
322 desired_y = MAKE_MATRIX_PTR(
float, 9, 1);
324 dy = MAKE_MATRIX_PTR(
float, 9, 1);
331 (*
layer.
p[
"W0x0"]) << 1, 0, 1, 0, 1, 0, 1, 0, 1;
334 (*x) << 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0;
335 (*desired_y) << 4, 3, 4, 2, 4, 3, 2, 3, 4;
344 mic::types::MatrixPtr<float>
x;
350 mic::types::MatrixPtr<float>
dy;
366 x = MAKE_MATRIX_PTR(
float, 25, 1);
368 desired_y = MAKE_MATRIX_PTR(
float, 4, 1);
370 dy = MAKE_MATRIX_PTR(
float, 4, 1);
382 (*
layer.
p[
"W0x0"]).enumerate();
386 (*desired_y) << 29, 47, 119, 137;
389 (*desired_dx) << 0,0,0,0, 1, 0,0,0, 2, 3, 0,0,0,0,0,0, 2, 0,0, 3, 4, 6, 0, 6, 9;
391 (*desired_dW) << 87, 93, 117, 123;
401 mic::types::MatrixPtr<float>
x;
407 mic::types::MatrixPtr<float>
dy;
430 x = MAKE_MATRIX_PTR(
float, 7*7*3, 1);
432 desired_y = MAKE_MATRIX_PTR(
float, 3*3*2, 1);
441 (*
layer.
p[
"W0x0"]) << 0, -1, 0, 0, 1, -1, 1, 1, -1;
442 (*
layer.
p[
"W0x1"]) << 1, 0, 1, 0, -1, -1, 1, 1, -1;
443 (*
layer.
p[
"W0x2"]) << 1, 1, 0, -1, 1, -1, 1, 0, 1;
446 (*
layer.
p[
"W1x0"]) << 1, 1, -1, -1, -1, 1, 0, -1, -1;
447 (*
layer.
p[
"W1x1"]) << 0, 1, 1, -1, 1, -1, 0, -1, -1;
448 (*
layer.
p[
"W1x2"]) << 0, 0, 0, 1, 1, -1, -1, 0, 1;
481 -2, 3, 10, 7, 12, 11, -1, -1, 0,
483 -5, -10, -6, 4, -3, 2, 2, 3, 6;
491 mic::types::MatrixPtr<float>
x;
511 x = MAKE_MATRIX_PTR(
float, 6, 5);
515 dy = MAKE_MATRIX_PTR(
float, 6, 1);
522 for (
size_t i=0; i<16; i++)
523 (*
layer.
p[
"W0x0"])(i) = i+1;
524 (*
layer.
p[
"W0x0"]).resize(4,4);
525 (*
layer.
p[
"W0x0"]).transposeInPlace();
527 (*
layer.
p[
"W0x0"]).resize(1, 4*4);
532 for (
size_t i=0; i<30; i++)
534 (*x).transposeInPlace();
538 (*desired_y) << 2064, 2880, 2200, 3016, 2336, 3152;
551 mic::types::MatrixPtr<float>
x;
557 mic::types::MatrixPtr<float>
dy;
574 x = MAKE_MATRIX_PTR(
double, 8*8, 1);
576 target_y = MAKE_MATRIX_PTR(
double, 2, 1);
585 (*x).randn(0, 6.0/(8*8));
599 mic::types::MatrixPtr<double>
x;
616 x = MAKE_MATRIX_PTR(
double, 28*28, 1);
618 target_y = MAKE_MATRIX_PTR(
double, 8, 1);
627 (*x).randn(0, 6.0/(8*8));
641 mic::types::MatrixPtr<double>
x;
mic::types::MatrixPtr< float > x
Test x - used in forward pass.
mic::neural_nets::loss::SquaredErrorLoss< double > loss
mic::types::MatrixPtr< double > desired_dW
Desired gradient dW from backpropagation.
mic::types::MatrixPtr< float > dy
Gradient passed to backpropagation.
mic::types::MatrixPtr< double > desired_db
Desired gradient db from backpropagation.
mic::types::MatrixPtr< double > dy
Gradient passed to backpropagation.
mic::mlnn::convolution::Convolution< double > layer
Object to be tested.
Test Fixture - layer of input size 4x4x1 and with filter bank of 3 filters of size 1x1 with stride 3...
mic::mlnn::convolution::Convolution< float > layer
Object to be tested.
mic::types::MatrixPtr< float > x
Test x - used in forward pass.
mic::neural_nets::loss::SquaredErrorLoss< double > loss
mic::types::MatrixPtr< float > desired_y
Desired output for a given x.
Conv4x4x1Filter3x1x1s3Double()
Conv5x5x1Filter1x2x2s3Float()
mic::types::MatrixPtr< float > desired_dx
Desired gradient dy from backpropagation.
mic::mlnn::convolution::Convolution< double > layer
Object to be tested.
mic::mlnn::convolution::Convolution< double > layer
Object to be tested.
mic::types::MatrixPtr< float > dy
Gradient passed to backpropagation.
mic::neural_nets::loss::SquaredErrorLoss< double > loss
mic::types::MatrixPtr< double > x
Test x - used in forward pass.
mic::types::MatrixPtr< double > desired_db
Desired gradient db from backpropagation.
mic::types::MatrixPtr< double > target_y
Target y values.
mic::mlnn::convolution::Convolution< float > layer
Object to be tested.
mic::types::MatrixPtr< float > desired_dx
Desired gradient dx from backpropagation.
Test Fixture - layer of input size 5x6x1 and with filter bank of 1 filter of size 4x4 with stride 1...
Conv8x8x1Filter2x4x4s4Double()
Conv28x28x1Filter2x28x28s1Double()
mic::types::MatrixPtr< float > desired_dx
Desired gradient dy from backpropagation.
mic::types::MatrixPtr< double > target_y
Target y values.
mic::types::MatrixPtr< double > x
Test x - used in forward pass.
Conv2x2x2Filter2x1x1s1Double()
Conv5x5x1Filter1x3x3s1Float()
mic::types::MatrixPtr< double > desired_dx
Target y values.
Conv5x6x1Filter1x4x4s1Float()
Test Fixture - layer of input size 4x4x1 and with filter bank of 1 filters of size 2x2 with stride 2...
mic::types::MatrixPtr< double > x
Test x - used in forward pass.
mic::mlnn::convolution::Convolution< double > layer
Object to be tested.
Test Fixture - layer of input size 2x2x2 and with filter bank of 2 filters of size 1x1 with stride 1...
mic::types::MatrixPtr< float > dy
Gradient passed to backpropagation.
Test Fixture - layer of input size 5x5x1 and with filter bank of 1 filter of size 3x3 with stride 1 (...
mic::neural_nets::loss::SquaredErrorLoss< double > loss
mic::types::MatrixPtr< float > desired_db
Desired gradient db from backpropagation.
mic::types::MatrixPtr< double > desired_dx
Desired gradient dx from backpropagation.
mic::types::MatrixPtr< double > desired_y
Desired output for a given x.
mic::types::MatrixPtr< float > desired_dW
Desired gradient dW from backpropagation.
Test Fixture - layer of input size 8x8x1 and with filter bank of 2 filters of size 4x4 with stride 4...
mic::types::MatrixPtr< float > desired_y
Desired output for a given x.
mic::mlnn::convolution::Convolution< float > layer
Object to be tested.
Test Fixture - layer of input size 3x3x2 and with filter bank of 3 filters of size 2x2 with stride 1...
Conv3x3x2Filter3x2x2s1Float()
mic::types::MatrixPtr< float > dy
Gradient passed to backpropagation.
Test Fixture - layer of input size 28x28x1 and with filter bank of 2 filters of size 28x28 with strid...
mic::types::MatrixPtr< float > desired_y
Desired output for a given x.
mic::types::MatrixPtr< double > desired_dW
Desired gradient dW from backpropagation.
mic::types::MatrixPtr< float > desired_y
Desired output for a given x.
mic::types::MatrixPtr< float > x
Test x - used in forward pass.
mic::types::MatrixPtr< double > dy
Gradient passed to backpropagation.
mic::types::MatrixPtr< float > desired_db
Desired gradient db from backpropagation.
mic::types::MatrixPtr< float > desired_y
Desired output for a given x.
mic::types::MatrixPtr< float > x
Test x - used in forward pass.
mic::types::MatrixPtr< double > desired_y
Desired output for a given x.
mic::mlnn::convolution::Convolution< float > layer
Object to be tested.
mic::types::MatrixPtr< float > desired_y
Desired output for a given x.
mic::types::MatrixPtr< double > target_y
Target y values.
Conv4x4x1Filter1x2x2s2Float()
mic::mlnn::convolution::Convolution< float > layer
Object to be tested.
Test Fixture - layer of input size 5x5x1 and with filter bank of 1 filter of size 2x2 with stride 3 (...
Conv7x7x3Filter3x3x3s2Float()
mic::types::MatrixPtr< float > desired_dW
Desired gradient dW from backpropagation.
mic::types::MatrixPtr< float > x
Test x - used in forward pass.
mic::mlnn::convolution::Convolution< float > layer
Object to be tested.
mic::types::MatrixPtr< float > x
Test x - used in forward pass.
Test Fixture - layer of input size 7x7x3 and with filter bank of 2 filters of 3x3 with stride 2 (floa...
mic::types::MatrixPtr< double > x
Test x - used in forward pass.
mic::types::MatrixArray< eT > p
Parameters - parameters of the layer, to be used by the derived classes.