diff --git a/mace/core/testing/test_benchmark.cc b/mace/core/testing/test_benchmark.cc index 41608a9530d744e58efaa22a1faa2bb612bd45aa..7e09c28fbe9c87041d3e8de31c2f42febc02c7eb 100644 --- a/mace/core/testing/test_benchmark.cc +++ b/mace/core/testing/test_benchmark.cc @@ -125,7 +125,7 @@ void Benchmark::Register() { } void Benchmark::Run(int arg1, int arg2, int* run_count, double* run_seconds) { - static const int64_t kMinIters = 100; + static const int64_t kMinIters = 10; static const int64_t kMaxIters = 1000000000; static const double kMinTime = 0.5; int64_t iters = kMinIters; diff --git a/mace/ops/batch_norm_test.cc b/mace/ops/batch_norm_test.cc index 21ee8c5613ad6a3f6aada28a8bc4fb98390d6c70..ca32ec753f20cfd9b34d096f30527d0b7cd9b99c 100644 --- a/mace/ops/batch_norm_test.cc +++ b/mace/ops/batch_norm_test.cc @@ -11,7 +11,7 @@ class BatchNormOpTest : public OpsTestBase {}; TEST_F(BatchNormOpTest, Simple) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("BatchNorm", "BatchNormTest") .Input("Input") .Input("Scale") @@ -19,25 +19,25 @@ TEST_F(BatchNormOpTest, Simple) { .Input("Mean") .Input("Var") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add input data - net->AddInputFromArray("Input", {1, 1, 6, 2}, + net.AddInputFromArray("Input", {1, 1, 6, 2}, {5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15}); - net->AddInputFromArray("Scale", {1}, {4.0f}); - net->AddInputFromArray("Offset", {1}, {2.0}); - net->AddInputFromArray("Mean", {1}, {10}); - net->AddInputFromArray("Var", {1}, {11.67f}); + net.AddInputFromArray("Scale", {1}, {4.0f}); + net.AddInputFromArray("Offset", {1}, {2.0}); + net.AddInputFromArray("Mean", {1}, {10}); + net.AddInputFromArray("Var", {1}, {11.67f}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 1, 6, 2}, {-3.86, -3.86, -1.51, -1.51, 0.83, 0.83, 3.17, 3.17, 5.51, 5.51, 7.86, 7.86}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.01); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.01); } } diff --git a/mace/ops/conv_2d_test.cc b/mace/ops/conv_2d_test.cc index b8af88ae1f1e8deb79d8e3058cea45a702a1d34d..43228e6acee4ffa2f0a6ecbaebf9bca408ba4738 100644 --- a/mace/ops/conv_2d_test.cc +++ b/mace/ops/conv_2d_test.cc @@ -12,73 +12,73 @@ class Conv2dOpTest : public OpsTestBase {}; TEST_F(Conv2dOpTest, Simple_VALID) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Conv2d", "Conv2dTest") .Input("Input") .Input("Filter") .Input("Bias") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("strides", {1, 1}); - net->AddIntArg("padding", Padding::VALID); - net->AddIntsArg("dilations", {1, 1}); + net.AddIntsArg("strides", {1, 1}); + net.AddIntArg("padding", Padding::VALID); + net.AddIntsArg("dilations", {1, 1}); // Add input data - net->AddInputFromArray("Input", {1, 2, 3, 3}, + net.AddInputFromArray("Input", {1, 2, 3, 3}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - net->AddInputFromArray("Filter", {1, 2, 3, 3}, + net.AddInputFromArray("Filter", {1, 2, 3, 3}, {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}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 1, 1, 1}, {18.1f}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } TEST_F(Conv2dOpTest, Simple_SAME) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Conv2d", "Conv2dTest") .Input("Input") .Input("Filter") .Input("Bias") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("strides", {1, 1}); - net->AddIntArg("padding", Padding::SAME); - net->AddIntsArg("dilations", {1, 1}); + net.AddIntsArg("strides", {1, 1}); + net.AddIntArg("padding", Padding::SAME); + net.AddIntsArg("dilations", {1, 1}); // Add input data - net->AddInputFromArray("Input", {1, 2, 3, 3}, + net.AddInputFromArray("Input", {1, 2, 3, 3}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - net->AddInputFromArray("Filter", {1, 2, 3, 3}, + net.AddInputFromArray("Filter", {1, 2, 3, 3}, {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}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 1, 3, 3}, @@ -86,26 +86,26 @@ TEST_F(Conv2dOpTest, Simple_SAME) { 12.1f, 18.1f, 12.1f, 8.1f, 12.1f, 8.1f}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } TEST_F(Conv2dOpTest, Combined) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Conv2d", "Conv2dTest") .Input("Input") .Input("Filter") .Input("Bias") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("strides", {2, 2}); - net->AddIntArg("padding", Padding::SAME); - net->AddIntsArg("dilations", {1, 1}); + net.AddIntsArg("strides", {2, 2}); + net.AddIntArg("padding", Padding::SAME); + net.AddIntsArg("dilations", {1, 1}); // Add input data - net->AddInputFromArray("Input", {1, 2, 5, 5}, + net.AddInputFromArray("Input", {1, 2, 5, 5}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -116,15 +116,15 @@ TEST_F(Conv2dOpTest, Combined) { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - net->AddInputFromArray("Filter", {2, 2, 3, 3}, + net.AddInputFromArray("Filter", {2, 2, 3, 3}, {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, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f}); - net->AddInputFromArray("Bias", {2}, {0.1f, 0.2f}); + net.AddInputFromArray("Bias", {2}, {0.1f, 0.2f}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 2, 3, 3}, @@ -136,26 +136,26 @@ TEST_F(Conv2dOpTest, Combined) { 4.2f, 6.2f, 4.2f}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } TEST_F(Conv2dOpTest, Conv1x1) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Conv2d", "Conv2dTest") .Input("Input") .Input("Filter") .Input("Bias") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("strides", {1, 1}); - net->AddIntArg("padding", Padding::VALID); - net->AddIntsArg("dilations", {1, 1}); + net.AddIntsArg("strides", {1, 1}); + net.AddIntArg("padding", Padding::VALID); + net.AddIntsArg("dilations", {1, 1}); // Add input data - net->AddInputFromArray("Input", {1, 5, 3, 10}, + net.AddInputFromArray("Input", {1, 5, 3, 10}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -171,13 +171,13 @@ TEST_F(Conv2dOpTest, Conv1x1) { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); - net->AddInputFromArray("Filter", {2, 5, 1, 1}, + net.AddInputFromArray("Filter", {2, 5, 1, 1}, {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f}); - net->AddInputFromArray("Bias", {2}, {0.1f, 0.2f}); + net.AddInputFromArray("Bias", {2}, {0.1f, 0.2f}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 2, 3, 10}, @@ -188,7 +188,7 @@ TEST_F(Conv2dOpTest, Conv1x1) { 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f, 10.2f}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } // TODO we need more tests diff --git a/mace/ops/ops_test_util.h b/mace/ops/ops_test_util.h index dbec589db8fb54cee3b19fc935232be7a603d0c0..991eee57821c3110a7a7d6d3f824889de467f607 100644 --- a/mace/ops/ops_test_util.h +++ b/mace/ops/ops_test_util.h @@ -136,7 +136,7 @@ class OpsTestNet { class OpsTestBase : public ::testing::Test { public: - OpsTestNet* test_net() { return &test_net_; }; + OpsTestNet& test_net() { return test_net_; }; protected: virtual void TearDown() { diff --git a/mace/ops/pooling_test.cc b/mace/ops/pooling_test.cc index 03831c7de7d7a7636063e224d5eeaa745900d6a0..761c792e08321e75491622e5f0d0be1740052913 100644 --- a/mace/ops/pooling_test.cc +++ b/mace/ops/pooling_test.cc @@ -15,21 +15,21 @@ class PoolingOpTest : public OpsTestBase {}; TEST_F(PoolingOpTest, MAX_VALID) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Pooling", "PoolingTest") .Input("Input") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("kernels", {2, 2}); - net->AddIntsArg("strides", {2, 2}); - net->AddIntArg("padding", Padding::VALID); - net->AddIntsArg("dilations", {1, 1}); - net->AddIntArg("pooling_type", PoolingType::MAX); + net.AddIntsArg("kernels", {2, 2}); + net.AddIntsArg("strides", {2, 2}); + net.AddIntArg("padding", Padding::VALID); + net.AddIntsArg("dilations", {1, 1}); + net.AddIntArg("pooling_type", PoolingType::MAX); // Add input data - net->AddInputFromArray("Input", {1, 2, 4, 4}, + net.AddInputFromArray("Input", {1, 2, 4, 4}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, @@ -40,33 +40,33 @@ TEST_F(PoolingOpTest, MAX_VALID) { 28, 29, 30, 31}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 2, 2, 2}, {5, 7, 13, 15, 21, 23, 29, 31}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } TEST_F(PoolingOpTest, AVG_VALID) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Pooling", "PoolingTest") .Input("Input") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("kernels", {2, 2}); - net->AddIntsArg("strides", {2, 2}); - net->AddIntArg("padding", Padding::VALID); - net->AddIntsArg("dilations", {1, 1}); - net->AddIntArg("pooling_type", PoolingType::AVG); + net.AddIntsArg("kernels", {2, 2}); + net.AddIntsArg("strides", {2, 2}); + net.AddIntArg("padding", Padding::VALID); + net.AddIntsArg("dilations", {1, 1}); + net.AddIntArg("pooling_type", PoolingType::AVG); // Add input data - net->AddInputFromArray("Input", {1, 2, 4, 4}, + net.AddInputFromArray("Input", {1, 2, 4, 4}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, @@ -77,74 +77,74 @@ TEST_F(PoolingOpTest, AVG_VALID) { 28, 29, 30, 31}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 2, 2, 2}, {2.5, 4.5, 10.5, 12.5, 18.5, 20.5, 26.5, 28.5}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } TEST_F(PoolingOpTest, MAX_SAME) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Pooling", "PoolingTest") .Input("Input") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("kernels", {2, 2}); - net->AddIntsArg("strides", {2, 2}); - net->AddIntArg("padding", Padding::SAME); - net->AddIntsArg("dilations", {1, 1}); - net->AddIntArg("pooling_type", PoolingType::MAX); + net.AddIntsArg("kernels", {2, 2}); + net.AddIntsArg("strides", {2, 2}); + net.AddIntArg("padding", Padding::SAME); + net.AddIntsArg("dilations", {1, 1}); + net.AddIntArg("pooling_type", PoolingType::MAX); // Add input data - net->AddInputFromArray("Input", {1, 1, 3, 3}, + net.AddInputFromArray("Input", {1, 1, 3, 3}, {0, 1, 2, 3, 4, 5, 6, 7, 8}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 1, 2, 2}, {4, 5, 7, 8}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } TEST_F(PoolingOpTest, MAX_VALID_DILATION) { // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("Pooling", "PoolingTest") .Input("Input") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add args - net->AddIntsArg("kernels", {2, 2}); - net->AddIntsArg("strides", {1, 1}); - net->AddIntArg("padding", Padding::VALID); - net->AddIntsArg("dilations", {2, 2}); - net->AddIntArg("pooling_type", PoolingType::MAX); + net.AddIntsArg("kernels", {2, 2}); + net.AddIntsArg("strides", {1, 1}); + net.AddIntArg("padding", Padding::VALID); + net.AddIntsArg("dilations", {2, 2}); + net.AddIntArg("pooling_type", PoolingType::MAX); // Add input data - net->AddInputFromArray("Input", {1, 1, 4, 4}, + net.AddInputFromArray("Input", {1, 1, 4, 4}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 1, 2, 2}, {10, 11, 14, 15}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } diff --git a/mace/ops/resize_bilinear_test.cc b/mace/ops/resize_bilinear_test.cc index d6ee33b62bcb7abe1fcf67f91ec16fe533e1b3ef..32c91721043236390d7fbe6e3388bf9e6dd54a05 100644 --- a/mace/ops/resize_bilinear_test.cc +++ b/mace/ops/resize_bilinear_test.cc @@ -13,51 +13,51 @@ class ResizeBilinearTest : public OpsTestBase {}; TEST_F(ResizeBilinearTest, ResizeBilinearWOAlignCorners) { testing::internal::LogToStderr(); // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("ResizeBilinear", "ResizeBilinearTest") .Input("Input") .Input("OutSize") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); // Add input data vector input(24); std::iota(begin(input), end(input), 0); - net->AddInputFromArray("Input", {1, 3, 2, 4}, input); - net->AddInputFromArray("OutSize", {2}, {1, 2}); + net.AddInputFromArray("Input", {1, 3, 2, 4}, input); + net.AddInputFromArray("OutSize", {2}, {1, 2}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 3, 1, 2}, {0, 2, 8, 10, 16, 18}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); } TEST_F(ResizeBilinearTest, ResizeBilinearWAlignCorners) { testing::internal::LogToStderr(); // Construct graph - auto net = test_net(); + auto& net = test_net(); OpDefBuilder("ResizeBilinear", "ResizeBilinearTest") .Input("Input") .Input("OutSize") .Output("Output") - .Finalize(net->operator_def()); + .Finalize(net.operator_def()); - net->AddIntArg("align_corners", 1); + net.AddIntArg("align_corners", 1); // Add input data vector input(24); std::iota(begin(input), end(input), 0); - net->AddInputFromArray("Input", {1, 3, 2, 4}, input); - net->AddInputFromArray("OutSize", {2}, {1, 2}); + net.AddInputFromArray("Input", {1, 3, 2, 4}, input); + net.AddInputFromArray("OutSize", {2}, {1, 2}); // Run - net->RunOp(); + net.RunOp(); // Check Tensor expected = CreateTensor({1, 3, 1, 2}, {0, 3, 8, 11, 16, 19}); - ExpectTensorNear(expected, *net->GetOutput("Output"), 0.001); + ExpectTensorNear(expected, *net.GetOutput("Output"), 0.001); }