diff --git a/mace/ops/addn_test.cc b/mace/ops/addn_test.cc index 37f409b61fa10166ab22188fbe4544e8c537385e..471d96ec3a4743821a8ad635205e5bb7b0ed8449 100644 --- a/mace/ops/addn_test.cc +++ b/mace/ops/addn_test.cc @@ -42,28 +42,60 @@ template void SimpleAdd3() { // Construct graph OpsTestNet net; - OpDefBuilder("AddN", "AddNTest") - .Input("Input1") - .Input("Input2") - .Input("Input3") - .Output("Output") - .Finalize(net.NewOperatorDef()); // Add input data - net.AddInputFromArray("Input1", {1, 2, 3, 1}, {1, 2, 3, 4, 5, 6}); - net.AddInputFromArray("Input2", {1, 2, 3, 1}, {1, 2, 3, 4, 5, 6}); - net.AddInputFromArray("Input3", {1, 2, 3, 1}, {1, 2, 3, 4, 5, 6}); + net.AddInputFromArray("Input0", {1, 2, 3, 1}, + {-2.06715, 2, 3, 4, 5, 6}); + net.AddInputFromArray("Input1", {1, 2, 3, 1}, + {0.875977, 2, 3, 4, 5, 6}); + net.AddInputFromArray("Input2", {1, 2, 3, 1}, + {1.34866, 2, 3, 4, 5, 6}); + net.AddInputFromArray("Input3", {1, 2, 3, 1}, + {-0.1582, 2, 3, 4, 5, 6}); + + const int input_num = 4; + if (D == DeviceType::OPENCL) { + // run on gpu + for (int i = 0; i < input_num; ++i) { + BufferToImage(&net, MakeString("Input", i), + MakeString("InputImage", i), + kernels::BufferType::IN_OUT_CHANNEL); + } - // Run - net.RunOp(D); + auto op_def_cl = OpDefBuilder("AddN", "AddNTest"); + for (int i = 0; i < input_num; ++i) { + op_def_cl.Input(MakeString("InputImage", i)); + } + op_def_cl.Output("OutputImage") + .AddIntArg("T", static_cast(DataType::DT_HALF)) + .Finalize(net.NewOperatorDef()); - auto expected = CreateTensor({1, 2, 3, 1}, {3, 6, 9, 12, 15, 18}); + // Run on device + net.RunOp(D); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); + ImageToBuffer(&net, "OutputImage", "Output", + kernels::BufferType::IN_OUT_CHANNEL); + } else { + OpDefBuilder("AddN", "AddNTest") + .Input("Input0") + .Input("Input1") + .Input("Input2") + .Input("Input3") + .Output("Output") + .Finalize(net.NewOperatorDef()); + // Run + net.RunOp(D); + } + + auto expected = CreateTensor({1, 2, 3, 1}, + {-0.000713, 8, 12, 16, 20, 24}); + + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-4, 1e-3); } } // namespace TEST_F(AddnOpTest, CPUSimpleAdd3) { SimpleAdd3(); } +TEST_F(AddnOpTest, GPUSimpleAdd3) { SimpleAdd3(); } namespace { template @@ -118,7 +150,8 @@ void RandomTest() { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.1); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-2, 1e-2); } } } // namespace diff --git a/mace/ops/batch_norm_test.cc b/mace/ops/batch_norm_test.cc index bb546a78524cc4c834ab0adc909f0adf9f7442af..d588eccd746a34acb987cee5b3fa2625253d1900 100644 --- a/mace/ops/batch_norm_test.cc +++ b/mace/ops/batch_norm_test.cc @@ -67,10 +67,11 @@ void Simple() { // Check auto expected = - CreateTensor({1, 6, 2, 1}, {-3.86, -3.86, -1.51, -1.51, 0.83, 0.83, - 3.17, 3.17, 5.51, 5.51, 7.86, 7.86}); + CreateTensor({1, 6, 2, 1}, {-3.8543, -3.8543, -1.5125, -1.5125, + 0.8291, 0.8291, 3.1708, 3.1708, + 5.5125, 5.5125, 7.8543, 7.8543}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-2); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-4); } } // namespace @@ -81,8 +82,8 @@ TEST_F(BatchNormOpTest, SimpleOPENCL) { Simple(); } TEST_F(BatchNormOpTest, SimpleRandomOPENCL) { // generate random input static unsigned int seed = time(NULL); - index_t batch = 1 + rand_r(&seed) % 10; - index_t channels = 3 + rand_r(&seed) % 50; + index_t batch = 1 + rand_r(&seed) % 5; + index_t channels = 3 + rand_r(&seed) % 25; index_t height = 64; index_t width = 64; @@ -146,7 +147,7 @@ TEST_F(BatchNormOpTest, SimpleRandomOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5, 1e-4); } TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) { @@ -218,14 +219,14 @@ TEST_F(BatchNormOpTest, SimpleRandomHalfOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.5); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2, 1e-2); } TEST_F(BatchNormOpTest, ComplexRandomOPENCL) { // generate random input static unsigned int seed = time(NULL); - index_t batch = 1 + rand_r(&seed) % 10; - index_t channels = 3 + rand_r(&seed) % 50; + index_t batch = 1 + rand_r(&seed) % 5; + index_t channels = 3 + rand_r(&seed) % 25; index_t height = 103; index_t width = 113; @@ -289,14 +290,14 @@ TEST_F(BatchNormOpTest, ComplexRandomOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5, 1e-4); } TEST_F(BatchNormOpTest, ComplexRandomHalfOPENCL) { // generate random input static unsigned int seed = time(NULL); - index_t batch = 1 + rand_r(&seed) % 10; - index_t channels = 3 + rand_r(&seed) % 50; + index_t batch = 1 + rand_r(&seed) % 5; + index_t channels = 3 + rand_r(&seed) % 25; index_t height = 103; index_t width = 113; @@ -361,7 +362,7 @@ TEST_F(BatchNormOpTest, ComplexRandomHalfOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.5); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2, 1e-2); } TEST_F(BatchNormOpTest, NEONTest) { @@ -418,7 +419,7 @@ TEST_F(BatchNormOpTest, NEONTest) { ExpectTensorNear(*net.GetOutput("OutputExptected"), *net.GetOutput("OutputNeon"), - 0.001); + 1e-5); } } // namespace test diff --git a/mace/ops/bias_add_test.cc b/mace/ops/bias_add_test.cc index ccfcc9451ceb8d6483d5a11652026746fae5c6ec..dc3bca0617e4b4ccf45a2f7c9508a10ce63d0db3 100644 --- a/mace/ops/bias_add_test.cc +++ b/mace/ops/bias_add_test.cc @@ -53,7 +53,7 @@ void BiasAddSimple() { {1, 6, 2, 1}, {5.5, 5.5, 7.5, 7.5, 9.5, 9.5, 11.5, 11.5, 13.5, 13.5, 15.5, 15.5}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-2); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -109,7 +109,7 @@ TEST_F(BiasAddOpTest, SimpleRandomOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5); } TEST_F(BiasAddOpTest, ComplexRandomOPENCL) { @@ -158,7 +158,7 @@ TEST_F(BiasAddOpTest, ComplexRandomOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5); } } // namespace test diff --git a/mace/ops/buffer_to_image_test.cc b/mace/ops/buffer_to_image_test.cc index 151abb8f4ceb4ae96c90c1d2c67258822396e377..679c326e8b5ea7669f1b97c20a50064c785866e3 100644 --- a/mace/ops/buffer_to_image_test.cc +++ b/mace/ops/buffer_to_image_test.cc @@ -143,7 +143,7 @@ void TestDiffTypeBidirectionTransform(const int type, // Check ExpectTensorNear(*net.GetOutput("Input"), *net.GetOutput("I2BOutput"), - 1e-2); + 1e-3, 1e-6); } } // namespace @@ -185,7 +185,7 @@ void TestStringHalfBidirectionTransform(const int type, // Check ExpectTensorNear(*net.GetOutput("Input"), *net.GetOutput("I2BOutput"), - 1e-2); + 1e-3, 1e-6); } } // namespace diff --git a/mace/ops/channel_shuffle_test.cc b/mace/ops/channel_shuffle_test.cc index 610a260a2a98a2f0768830b831ad28e215eae53d..02bbaf2af807b00531e73ce1bf31f9af21df78a0 100644 --- a/mace/ops/channel_shuffle_test.cc +++ b/mace/ops/channel_shuffle_test.cc @@ -32,7 +32,7 @@ TEST_F(ChannelShuffleOpTest, C8G4_CPU) { auto expected = CreateTensor( {1, 1, 2, 8}, {0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } TEST_F(ChannelShuffleOpTest, C16G4_OPENCL) { @@ -66,7 +66,7 @@ TEST_F(ChannelShuffleOpTest, C16G4_OPENCL) { {0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 16, 20, 24, 28, 17, 21, 25, 29, 18, 22, 26, 30, 19, 23, 27, 31}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace test diff --git a/mace/ops/conv_2d_test.cc b/mace/ops/conv_2d_test.cc index b56f924c255b58bae092620fb76169447365e67a..a9707ab8469174efed16fcc33485b00fa3c2897a 100644 --- a/mace/ops/conv_2d_test.cc +++ b/mace/ops/conv_2d_test.cc @@ -68,7 +68,7 @@ void TestNHWCSimple3x3VALID() { } auto expected = CreateTensor({1, 1, 1, 1}, {18.1f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.01); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } template @@ -128,7 +128,7 @@ void TestNHWCSimple3x3SAME() { {1, 3, 3, 1}, {8.1f, 12.1f, 8.1f, 12.1f, 18.1f, 12.1f, 8.1f, 12.1f, 8.1f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.01); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -194,7 +194,7 @@ void TestNHWCSimple3x3WithoutBias() { // Check auto expected = CreateTensor({1, 1, 1, 1}, {18.0f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.01); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -266,7 +266,7 @@ void TestNHWCCombined3x3() { auto expected = CreateTensor( {1, 3, 3, 2}, {8.1f, 4.2f, 12.1f, 6.2f, 8.1f, 4.2f, 12.1f, 6.2f, 18.1f, 9.2f, 12.1f, 6.2f, 8.1f, 4.2f, 12.1f, 6.2f, 8.1f, 4.2f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.01); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -345,7 +345,7 @@ void TestConv1x1() { 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -415,7 +415,8 @@ void TestComplexConvNxNS12(const std::vector &shape, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.001); + ExpectTensorNear(expected, + *net.GetOutput("OPENCLOutput"), 1e-5, 1e-4); }; for (int kernel_size : {1, 3, 7}) { @@ -516,7 +517,8 @@ void TestHalfComplexConvNxNS12(const std::vector &input_shape, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.5); + ExpectTensorNear(expected, + *net.GetOutput("OPENCLOutput"), 1e-2, 1e-1); }; func(1, 1, VALID); @@ -641,7 +643,8 @@ void TestDilationConvNxN(const std::vector &shape, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5, 1e-4); }; for (int kernel_size : {3}) { @@ -725,7 +728,8 @@ void TestArbitraryPadConvNxN(const std::vector &shape, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5, 1e-4); }; for (int kernel_size : {3, 5}) { @@ -807,7 +811,7 @@ static void TestNeonArbitraryPadConvNxN(const std::vector &shape, ExpectTensorNear(*net.GetOutput("OutputExptected"), *net.GetOutput("OutputNeon"), - 0.001); + 1e-5, 1e-3); }; for (int kernel_size : {1, 3, 5}) { diff --git a/mace/ops/cwise_test.cc b/mace/ops/cwise_test.cc index 0ae24fd52c0233b2618c6548b90861f74e11af80..56b4359a14c605635d0fd090fb640c228ffa96ab 100644 --- a/mace/ops/cwise_test.cc +++ b/mace/ops/cwise_test.cc @@ -54,7 +54,7 @@ void Simple(const kernels::CWiseType type, auto expected = CreateTensor(shape, output); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-3); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5, 1e-3); } } // namespace @@ -140,10 +140,10 @@ void RandomTest(const kernels::CWiseType type, if (DataTypeToEnum::value == DT_FLOAT) { ExpectTensorNear(*net.GetTensor("Output"), - *net.GetOutput("OPENCLOutput"), 1e-3); + *net.GetOutput("OPENCLOutput"), 1e-5, 1e-4); } else { ExpectTensorNear(*net.GetTensor("Output"), - *net.GetOutput("OPENCLOutput"), 1e-1); + *net.GetOutput("OPENCLOutput"), 1e-2, 1e-2); } } } // namespace diff --git a/mace/ops/depth_to_space_test.cc b/mace/ops/depth_to_space_test.cc index 93cfac5863da6a142c290d0239fa169c0b959399..f96dfb4d3f1713d6ce21838a211a6db900f65700 100644 --- a/mace/ops/depth_to_space_test.cc +++ b/mace/ops/depth_to_space_test.cc @@ -48,7 +48,7 @@ void RunDepthToSpace(const bool d2s, kernels::BufferType::IN_OUT_CHANNEL); } auto expected = CreateTensor(expected_shape, expected_data); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -194,10 +194,10 @@ void RandomTest(const bool d2s, const int block_size, if (DataTypeToEnum::value == DT_FLOAT) { ExpectTensorNear(*net.GetTensor("Output"), - *net.GetOutput("OPENCLOutput"), 1e-3); + *net.GetOutput("OPENCLOutput"), 1e-5); } else { ExpectTensorNear(*net.GetTensor("Output"), - *net.GetOutput("OPENCLOutput"), 1e-1); + *net.GetOutput("OPENCLOutput"), 1e-3, 1e-4); } } } // namespace diff --git a/mace/ops/depthwise_conv2d_test.cc b/mace/ops/depthwise_conv2d_test.cc index 73bdceb5605d2e49f5063f6a966eed2c0d83f3a5..50d9a1f7de9ed8c70e44db904e7c331b496d3b82 100644 --- a/mace/ops/depthwise_conv2d_test.cc +++ b/mace/ops/depthwise_conv2d_test.cc @@ -46,8 +46,8 @@ void SimpleValidTest() { net.RunOp(D); // Transfer output - ImageToBuffer(&net, "OutputImage", "Output", - kernels::BufferType::IN_OUT_CHANNEL); + ImageToBuffer(&net, "OutputImage", "Output", + kernels::BufferType::IN_OUT_CHANNEL); } else { OpDefBuilder("DepthwiseConv2d", "DepthwiseConv2DTest") @@ -64,11 +64,15 @@ void SimpleValidTest() { } // Check - auto expected = CreateTensor( - {1, 2, 2, 2}, VectorStaticCast({37.1f, 148.2f, 47.1f, 188.2f, 67.1f, - 268.2f, 77.1f, 308.2f})); + auto expected = CreateTensor( + {1, 2, 2, 2}, {37.1f, 148.2f, 47.1f, 188.2f, + 67.1f, 268.2f, 77.1f, 308.2f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); + if (DataTypeToEnum::value == DT_HALF) { + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-3, 1e-3); + } else { + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); + } } } // namespace @@ -189,7 +193,11 @@ void ComplexValidTest() { 9.13650036, 8.5095005, 8.92500019, 9.34349918, 8.69849968, 9.12300014, 9.55049992, 4.55220032, 4.80690002, 5.06340027})); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.2); + if (DataTypeToEnum::value == DT_FLOAT) { + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); + } else { + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-2); + } } } // namespace @@ -282,7 +290,13 @@ void TestNxNS12(const index_t height, const index_t width) { } // Check - ExpectTensorNear(expected, *net.GetOutput("DeviceOutput"), 0.1); + if (DataTypeToEnum::value == DT_FLOAT) { + ExpectTensorNear(expected, *net.GetOutput("DeviceOutput"), + 1e-5, 1e-4); + } else { + ExpectTensorNear(expected, *net.GetOutput("DeviceOutput"), + 1e-2, 1e-2); + } }; for (int kernel_size : {2, 3, 4}) { @@ -303,12 +317,10 @@ TEST_F(DepthwiseConv2dOpTest, OpenCLSimpleNxNS12Half) { } TEST_F(DepthwiseConv2dOpTest, OpenCLAlignedNxNS12) { - TestNxNS12(64, 64); TestNxNS12(128, 128); } TEST_F(DepthwiseConv2dOpTest, OpenCLAlignedNxNS12Half) { - TestNxNS12(64, 64); TestNxNS12(128, 128); } @@ -380,7 +392,7 @@ void TestNEONNxNS12(const index_t height, // Check ExpectTensorNear(*net.GetOutput("OutputExptected"), *net.GetOutput("OutputNeon"), - 0.001); + 1e-5, 1e-3); }; for (int kernel_size : {1, 3, 5}) { diff --git a/mace/ops/eltwise_test.cc b/mace/ops/eltwise_test.cc index 36dea470f8b9e9f5a783a176cad43bda4494c4f4..a489607730dfe955f73fec36788039ab75ba9efa 100644 --- a/mace/ops/eltwise_test.cc +++ b/mace/ops/eltwise_test.cc @@ -60,7 +60,7 @@ void Simple(const kernels::EltwiseType type, auto expected = CreateTensor(shape, output); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-3); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -146,10 +146,10 @@ void RandomTest(const kernels::EltwiseType type, if (DataTypeToEnum::value == DT_FLOAT) { ExpectTensorNear(*net.GetTensor("Output"), - *net.GetOutput("OPENCLOutput"), 1e-3); + *net.GetOutput("OPENCLOutput"), 1e-5, 1e-4); } else { ExpectTensorNear(*net.GetTensor("Output"), - *net.GetOutput("OPENCLOutput"), 1e-1); + *net.GetOutput("OPENCLOutput"), 1e-2, 1e-2); } } } // namespace diff --git a/mace/ops/folded_batch_norm_test.cc b/mace/ops/folded_batch_norm_test.cc index d46e161570a922c8f51f9e06913f713a2e6b8f82..d422bb041c007e05d229c192dbcdd68ad1a82c0d 100644 --- a/mace/ops/folded_batch_norm_test.cc +++ b/mace/ops/folded_batch_norm_test.cc @@ -72,10 +72,11 @@ void Simple() { // Check auto expected = - CreateTensor({1, 6, 2, 1}, {-3.86, -3.86, -1.51, -1.51, 0.83, 0.83, - 3.17, 3.17, 5.51, 5.51, 7.86, 7.86}); + CreateTensor({1, 6, 2, 1}, {-3.8543, -3.8543, -1.5125, -1.5125, + 0.8291, 0.8291, 3.1708, 3.1708, + 5.5125, 5.5125, 7.8543, 7.8543}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-2); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-4); } } // namespace @@ -226,7 +227,7 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5, 1e-4); } TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) { @@ -281,7 +282,7 @@ TEST_F(FoldedBatchNormOpTest, SimpleRandomHalfOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.5); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2, 1e-2); } TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) { @@ -334,7 +335,7 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5, 1e-4); } TEST_F(FoldedBatchNormOpTest, ComplexRandomHalfOPENCL) { @@ -388,7 +389,7 @@ TEST_F(FoldedBatchNormOpTest, ComplexRandomHalfOPENCL) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.5); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2, 1e-2); } } // namespace test diff --git a/mace/ops/fully_connected_test.cc b/mace/ops/fully_connected_test.cc index 349acc7f03c30aaa57faa76eaeacc621f1624f32..d4c17fb42fdabfe02709e7c2a8268b6fa138ffcd 100644 --- a/mace/ops/fully_connected_test.cc +++ b/mace/ops/fully_connected_test.cc @@ -164,9 +164,11 @@ void Complex(const index_t batch, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); if (DataTypeToEnum::value == DataType::DT_HALF) { - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-1, 1e-1); } else { - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-3); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5, 1e-4); } } } // namespace @@ -247,9 +249,11 @@ void TestWXFormat(const index_t batch, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); if (DataTypeToEnum::value == DataType::DT_HALF) { - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-1, 1e-1); } else { - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-3, 1e-3); } } } // namespace @@ -267,7 +271,7 @@ TEST_F(FullyConnectedOpTest, OPENCLWidthFormatMultiBatch) { } TEST_F(FullyConnectedOpTest, OPENCLHalfWidthFormatAligned) { - TestWXFormat(1, 2, 2, 512, 2); + TestWXFormat(1, 2, 2, 512, 2); TestWXFormat(1, 11, 11, 32, 16); TestWXFormat(1, 16, 32, 32, 32); } @@ -315,7 +319,7 @@ void FullyConnectedTestNEON(const index_t batch, ExpectTensorNear(*net.GetOutput("OutputExptected"), *net.GetOutput("OutputNeon"), - 0.01); + 1e-3, 1e-3); } } // namespace diff --git a/mace/ops/fused_conv_2d_test.cc b/mace/ops/fused_conv_2d_test.cc index e0fb62457254ead8b07dbcc45c74923f33b26525..6ef1298386a8114505bd82aeb30114b1792cb71b 100644 --- a/mace/ops/fused_conv_2d_test.cc +++ b/mace/ops/fused_conv_2d_test.cc @@ -18,14 +18,14 @@ template void TestNHWCSimple3x3VALID() { OpsTestNet net; // Add input data - net.AddInputFromArray( + net.AddInputFromArray( "Input", {1, 3, 3, 2}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}); - net.AddInputFromArray( + net.AddInputFromArray( "Filter", {3, 3, 1, 2}, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); - net.AddInputFromArray("Bias", {1}, {-0.1f}); + net.AddInputFromArray("Bias", {1}, {-0.1f}); if (D == DeviceType::OPENCL) { BufferToImage(&net, "Input", "InputImage", @@ -49,8 +49,8 @@ void TestNHWCSimple3x3VALID() { net.RunOp(D); // Transfer output - ImageToBuffer(&net, "OutputImage", "Output", - kernels::BufferType::IN_OUT_CHANNEL); + ImageToBuffer(&net, "OutputImage", "Output", + kernels::BufferType::IN_OUT_CHANNEL); } else { OpDefBuilder("FusedConv2D", "FusedConv2dTest") @@ -69,7 +69,7 @@ void TestNHWCSimple3x3VALID() { } auto expected = CreateTensor({1, 1, 1, 1}, {0.0f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.01); + ExpectTensorNear(*expected, *net.GetOutput("Output")); } template @@ -77,14 +77,14 @@ void TestNHWCSimple3x3SAME() { OpsTestNet net; // Add input data - net.AddInputFromArray( + net.AddInputFromArray( "Input", {1, 3, 3, 2}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}); - net.AddInputFromArray( + net.AddInputFromArray( "Filter", {3, 3, 1, 2}, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); - net.AddInputFromArray("Bias", {1}, {-0.1f}); + net.AddInputFromArray("Bias", {1}, {-0.1f}); if (D == DeviceType::OPENCL) { BufferToImage(&net, "Input", "InputImage", @@ -108,8 +108,8 @@ void TestNHWCSimple3x3SAME() { net.RunOp(D); // Transfer output - ImageToBuffer(&net, "OutputImage", "Output", - kernels::BufferType::IN_OUT_CHANNEL); + ImageToBuffer(&net, "OutputImage", "Output", + kernels::BufferType::IN_OUT_CHANNEL); } else { OpDefBuilder("FusedConv2D", "FusedConv2dTest") @@ -130,7 +130,7 @@ void TestNHWCSimple3x3SAME() { auto expected = CreateTensor( {1, 3, 3, 1}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.01); + ExpectTensorNear(*expected, *net.GetOutput("Output")); } } // namespace @@ -150,10 +150,10 @@ void TestNHWCSimple3x3WithoutBias() { OpsTestNet net; // Add input data - net.AddInputFromArray( + net.AddInputFromArray( "Input", {1, 3, 3, 2}, {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}); - net.AddInputFromArray( + net.AddInputFromArray( "Filter", {3, 3, 1, 2}, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); @@ -177,8 +177,8 @@ void TestNHWCSimple3x3WithoutBias() { // Run net.RunOp(D); // Transfer output - ImageToBuffer(&net, "OutputImage", "Output", - kernels::BufferType::IN_OUT_CHANNEL); + ImageToBuffer(&net, "OutputImage", "Output", + kernels::BufferType::IN_OUT_CHANNEL); } else { OpDefBuilder("FusedConv2D", "FusedConv2dTest") .Input("Input") @@ -198,7 +198,7 @@ void TestNHWCSimple3x3WithoutBias() { // Check auto expected = CreateTensor({1, 1, 1, 1}, {0.0f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.01); + ExpectTensorNear(*expected, *net.GetOutput("Output")); } } // namespace @@ -277,7 +277,7 @@ void TestConv1x1() { 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f, 5.1f, 10.2f}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output")); } } // namespace @@ -346,7 +346,8 @@ void TestComplexConvNxNS12(const std::vector &shape) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5, 1e-4); }; for (int kernel_size : {1, 3}) { @@ -434,7 +435,8 @@ void TestHalfComplexConvNxNS12(const std::vector &shape) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.2); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-2, 1e-1); }; for (int kernel_size : {1, 3}) { @@ -513,7 +515,8 @@ void TestGeneralConvNxNS12(const std::vector &image_shape, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5, 1e-4); }; for (int stride : {1, 2}) { @@ -594,7 +597,8 @@ void TestAtrousConvNxN(const std::vector &shape, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5, 1e-4); }; for (int kernel_size : {3}) { @@ -683,7 +687,8 @@ void TestGeneralHalfAtrousConv(const std::vector &image_shape, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.7); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-2, 1e-1); }; func(1, 1, VALID); @@ -763,7 +768,7 @@ void TestNEONGeneralConvNxNS12( ExpectTensorNear(*net.GetOutput("OutputExptected"), *net.GetOutput("OutputNeon"), - 0.001); + 1e-5, 1e-4); }; for (int stride : {1, 2}) { diff --git a/mace/ops/global_avg_pooling_test.cc b/mace/ops/global_avg_pooling_test.cc index 8b82f7ab4e3c9e8a98d0cf5549028a3a4d691a9f..e211268801fded1e632e13aa4ad1dc61e05723ae 100644 --- a/mace/ops/global_avg_pooling_test.cc +++ b/mace/ops/global_avg_pooling_test.cc @@ -31,7 +31,7 @@ TEST_F(GlobalAvgPoolingOpTest, 3x7x7_CPU) { // Check auto expected = CreateTensor({1, 3, 1, 1}, {1, 2, 3}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace test diff --git a/mace/ops/matmul_test.cc b/mace/ops/matmul_test.cc index afd92df2333f1e378528ec640e01d5b91d91619c..d5fea8569279a3e7bebe9f4a332325498ecaabdb 100644 --- a/mace/ops/matmul_test.cc +++ b/mace/ops/matmul_test.cc @@ -148,9 +148,11 @@ void Complex(const index_t batch, ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_HEIGHT); if (DataTypeToEnum::value == DataType::DT_HALF) { - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-1); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-2, 1e-1); } else { - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-4); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5, 1e-5); } } } // namespace diff --git a/mace/ops/ops_test_util.h b/mace/ops/ops_test_util.h index 595f8000348ad4a8087fc01787d0d2e5932a3b80..aca7853da53c7cff137921f6d6606b9169165dd4 100644 --- a/mace/ops/ops_test_util.h +++ b/mace/ops/ops_test_util.h @@ -439,7 +439,9 @@ struct Expector { } } - static void Near(const Tensor &x, const Tensor &y, const double abs_err) { + static void Near(const Tensor &x, const Tensor &y, + const double rel_err, + const double abs_err) { ASSERT_EQ(x.dtype(), DataTypeToEnum::v()); ASSERT_EQ(y.dtype(), DataTypeToEnum::v()); AssertSameDims(x, y); @@ -452,8 +454,9 @@ struct Expector { for (int h = 0; h < x.dim(1); ++h) { for (int w = 0; w < x.dim(2); ++w) { for (int c = 0; c < x.dim(3); ++c) { - EXPECT_NEAR(*a, *b, abs_err) << "with index = [" << n << ", " << h - << ", " << w << ", " << c << "]"; + const double error = abs_err + rel_err * std::abs(*a); + EXPECT_NEAR(*a, *b, error) << "with index = [" << n << ", " << h + << ", " << w << ", " << c << "]"; a++; b++; } @@ -462,26 +465,31 @@ struct Expector { } } else { for (int i = 0; i < x.size(); ++i) { - EXPECT_NEAR(a[i], b[i], abs_err) << "a = " << a << " b = " << b - << " index = " << i; + const double error = abs_err + rel_err * std::abs(a[i]); + EXPECT_NEAR(a[i], b[i], error) << "a = " << a << " b = " << b + << " index = " << i; } } } }; template -void ExpectTensorNear(const Tensor &x, const Tensor &y, const double abs_err) { +void ExpectTensorNear(const Tensor &x, const Tensor &y, + const double rel_err = 1e-5, + const double abs_err = 1e-8) { static_assert(is_floating_point_type::value, "T is not a floating point type"); - Expector::Near(x, y, abs_err); + Expector::Near(x, y, rel_err, abs_err); } template -void ExpectTensorNear(const Tensor &x, const Tensor &y, const double abs_err) { +void ExpectTensorNear(const Tensor &x, const Tensor &y, + const double rel_err = 1e-5, + const double abs_err = 1e-8) { static_assert(is_floating_point_type::value && is_floating_point_type::value, "T is not a floating point type"); - Expector::Near(x, y, abs_err); + Expector::Near(x, y, rel_err, abs_err); } template diff --git a/mace/ops/pad_test.cc b/mace/ops/pad_test.cc index 14d30ca5950f84c2c22a995669a05cec10889375..5a87f32a2219f47815c68fe32f835c89adc278be 100644 --- a/mace/ops/pad_test.cc +++ b/mace/ops/pad_test.cc @@ -137,7 +137,7 @@ void Complex(const std::vector &input_shape, auto output = net.GetTensor("OpenCLOutput"); if (DataTypeToEnum::value == DT_HALF) { - ExpectTensorNear(expected, *output, 1e-1); + ExpectTensorNear(expected, *output, 1e-2, 1e-2); } else { ExpectTensorNear(expected, *output, 1e-5); } diff --git a/mace/ops/pooling_test.cc b/mace/ops/pooling_test.cc index d65af7c611b9f4f6acb80c3e4901d0046efb1821..27d4cf891fa8abd44754a6b8f70c5425e5b9103c 100644 --- a/mace/ops/pooling_test.cc +++ b/mace/ops/pooling_test.cc @@ -41,7 +41,7 @@ TEST_F(PoolingOpTest, MAX_VALID) { auto expected = CreateTensor({1, 2, 2, 2}, {5, 21, 7, 23, 13, 29, 15, 31}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } TEST_F(PoolingOpTest, MAX_SAME) { @@ -67,7 +67,7 @@ TEST_F(PoolingOpTest, MAX_SAME) { // Check auto expected = CreateTensor({1, 2, 2, 1}, {4, 5, 7, 8}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } TEST_F(PoolingOpTest, MAX_VALID_DILATION) { @@ -94,7 +94,7 @@ TEST_F(PoolingOpTest, MAX_VALID_DILATION) { // Check auto expected = CreateTensor({1, 2, 2, 1}, {10, 11, 14, 15}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } TEST_F(PoolingOpTest, MAX_k2x2s2x2) { @@ -120,7 +120,7 @@ TEST_F(PoolingOpTest, MAX_k2x2s2x2) { // Check auto expected = CreateTensor({1, 1, 5, 1}, {10, 12, 14, 16, 17}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } namespace { @@ -167,7 +167,7 @@ void SimpleMaxPooling3S2() { // Check auto expected = CreateTensor({1, 1, 4, 1}, {20, 22, 24, 26}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -192,11 +192,10 @@ void MaxPooling3S2(const std::vector &input_shape, .AddIntsArg("strides", strides) .AddIntArg("padding", padding) .AddIntsArg("dilations", {1, 1}) - .AddIntArg("T", static_cast(DataTypeToEnum::value)) .Finalize(net.NewOperatorDef()); // Add input data - net.AddRandomInput("Input", input_shape); + net.AddRandomInput("Input", input_shape); // run on cpu net.RunOp(); @@ -216,10 +215,15 @@ void MaxPooling3S2(const std::vector &input_shape, .AddIntArg("T", static_cast(DataTypeToEnum::value)) .Finalize(net.NewOperatorDef()); net.RunOp(D); - ImageToBuffer(&net, "OutputImage", "OPENCLOutput", + ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.001); + if (DataTypeToEnum::value == DT_HALF) { + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-3, 1e-4); + } else { + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5); + } } } // namespace @@ -276,7 +280,7 @@ TEST_F(PoolingOpTest, AVG_VALID) { auto expected = CreateTensor( {1, 2, 2, 2}, {2.5, 18.5, 4.5, 20.5, 10.5, 26.5, 12.5, 28.5}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } namespace { @@ -309,7 +313,7 @@ void SimpleAvgPoolingTest() { // Check auto expected = CreateTensor({1, 1, 4, 1}, {4.5, 6.5, 8.5, 10.5}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -356,10 +360,17 @@ void AvgPoolingTest(const std::vector &shape, .AddIntArg("T", static_cast(DataTypeToEnum::value)) .Finalize(net.NewOperatorDef()); net.RunOp(D); - ImageToBuffer(&net, "OutputImage", "OPENCLOutput", + ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 0.01); + + if (DataTypeToEnum::value == DT_HALF) { + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-3, 1e-3); + } else { + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5); + } } } // namespace @@ -448,7 +459,7 @@ void AvgPoolingNEONTest(const std::vector &shape, ExpectTensorNear(*net.GetOutput("OutputExptected"), *net.GetOutput("OutputNeon"), - 0.01); + 1e-5, 1e-4); } } // namespace diff --git a/mace/ops/resize_bilinear_test.cc b/mace/ops/resize_bilinear_test.cc index cd1b81d0eec455c8554adaa5a46807501144cf15..3629ed01dcfcf350f84f16c7872c2cc6283ac842 100644 --- a/mace/ops/resize_bilinear_test.cc +++ b/mace/ops/resize_bilinear_test.cc @@ -35,7 +35,7 @@ TEST_F(ResizeBilinearTest, CPUResizeBilinearWOAlignCorners) { // Check auto expected = CreateTensor({1, 1, 2, 3}, {0, 1, 2, 6, 7, 8}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } TEST_F(ResizeBilinearTest, ResizeBilinearWAlignCorners) { @@ -60,7 +60,7 @@ TEST_F(ResizeBilinearTest, ResizeBilinearWAlignCorners) { // Check auto expected = CreateTensor({1, 1, 2, 3}, {0, 1, 2, 9, 10, 11}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 0.001); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } namespace { @@ -113,7 +113,8 @@ void TestRandomResizeBilinear() { // TODO(someone): support NEON } // Check - ExpectTensorNear(expected, *net.GetOutput("DeviceOutput"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("DeviceOutput"), + 1e-5, 1e-6); } } } // namespace diff --git a/mace/ops/softmax_test.cc b/mace/ops/softmax_test.cc index 156b84d3ef302662fb419d933d9634f5d40f507f..e8a7c48ea42758eb1fd6ffdc1064ea44c453a795 100644 --- a/mace/ops/softmax_test.cc +++ b/mace/ops/softmax_test.cc @@ -49,7 +49,7 @@ void Simple() { {1, 1, 2, 4}, {0.25, 0.25, 0.25, 0.25, 0.0320586, 0.08714432, 0.23688282, 0.64391426}); - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-7); + ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-5); } } // namespace @@ -89,7 +89,8 @@ void Complex(const std::vector &logits_shape) { ImageToBuffer(&net, "OutputImage", "OPENCLOutput", kernels::BufferType::IN_OUT_CHANNEL); - ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), 1e-5); + ExpectTensorNear(expected, *net.GetOutput("OPENCLOutput"), + 1e-5); } } // namespace @@ -138,7 +139,7 @@ void SoftMaxNEONTest(const std::vector &logits_shape) { ExpectTensorNear(*net.GetOutput("OutputExptected"), *net.GetOutput("OutputNeon"), - 0.01); + 1e-5, 1e-5); } } // namespace diff --git a/mace/ops/space_to_batch_test.cc b/mace/ops/space_to_batch_test.cc index a62b3493026615a8976b0d0dfcf23d69f5759ae2..a9ae67aca875efc7f98df8c0a744407c77d8ecf1 100644 --- a/mace/ops/space_to_batch_test.cc +++ b/mace/ops/space_to_batch_test.cc @@ -36,7 +36,7 @@ void RunSpaceToBatch(const std::vector &input_shape, ImageToBuffer(&net, "OutputImage", "Output", kernels::BufferType::IN_OUT_CHANNEL); // Check - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-8); + ExpectTensorNear(*expected, *net.GetOutput("Output")); } template @@ -64,7 +64,7 @@ void RunBatchToSpace(const std::vector &input_shape, ImageToBuffer(&net, "OutputImage", "Output", kernels::BufferType::IN_OUT_CHANNEL); // Check - ExpectTensorNear(*expected, *net.GetOutput("Output"), 1e-8); + ExpectTensorNear(*expected, *net.GetOutput("Output")); } template diff --git a/mace/ops/transpose_test.cc b/mace/ops/transpose_test.cc index bd61e132b5659cbd865a63d9037dc9f1e05c0cbc..929ac2c0b6d317a9ab40f1a8831ea07d8dbbaf92 100644 --- a/mace/ops/transpose_test.cc +++ b/mace/ops/transpose_test.cc @@ -30,8 +30,7 @@ void TransposeNCHWTest(const std::vector &input_shape) { net.FillNHWCInputToNCHWInput("InputNCHW", "Input"); ExpectTensorNear(*net.GetOutput("InputNCHW"), - *net.GetOutput("Output"), - 0.01); + *net.GetOutput("Output")); } } // namespace diff --git a/mace/ops/winograd_convolution_test.cc b/mace/ops/winograd_convolution_test.cc index ce9bcdca6b27f9ef34cb73130db79b50c1db7cc9..409f9cb3e20e3eb3e16cd269dd53e06b6e0e22f5 100644 --- a/mace/ops/winograd_convolution_test.cc +++ b/mace/ops/winograd_convolution_test.cc @@ -127,9 +127,11 @@ void WinogradConvolution(const index_t batch, ImageToBuffer(&net, "WinoOutputImage", "WinoOutput", kernels::BufferType::IN_OUT_CHANNEL); if (DataTypeToEnum::value == DataType::DT_HALF) { - ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), 1e-1); + ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), + 1e-2, 1e-2); } else { - ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), 1e-4); + ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), + 1e-5, 1e-4); } } } // namespace @@ -246,9 +248,11 @@ void WinogradConvolutionWithPad(const index_t batch, ImageToBuffer(&net, "WinoOutputImage", "WinoOutput", kernels::BufferType::IN_OUT_CHANNEL); if (DataTypeToEnum::value == DataType::DT_HALF) { - ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), 1e-1); + ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), + 1e-2, 1e-2); } else { - ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), 1e-3); + ExpectTensorNear(expected, *net.GetOutput("WinoOutput"), + 1e-5, 1e-4); } } } // namespace