Commit ba59b80b authored by Adam Rogowiec's avatar Adam Rogowiec Committed by Robert Kimball

[ONNX] Tests for reduction ops. (#1589)

* Add missing header.

* Test for ReduceSum

* Simple tests for reductions

- L1/L2/LogSum/LogSumExp/Max/Mean/Min/Prod/SumSquare.

* Add floating point literal suffix

* Fix typo
parent 2d0721d5
......@@ -28,6 +28,7 @@
#include "ngraph/axis_set.hpp"
#include "ngraph/node_vector.hpp"
#include "ngraph/op/reshape.hpp"
#include "ngraph/op/util/arithmetic_reduction.hpp"
#include "ngraph/shape.hpp"
#include "core/node.hpp"
......
ONNXNgraphImporter:O

AB"ReduceL1 compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:O

AB"ReduceL2 compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:S

AB" ReduceLogSum compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:V

AB"ReduceLogSumExp compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:P

AB" ReduceMax compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:Q

AB"
ReduceMean compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:P

AB" ReduceMin compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:Q

AB"
ReduceProd compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:P

AB" ReduceSum compute_graphZ
A




b
B

B
\ No newline at end of file
ONNXNgraphImporter:V

AB"ReduceSumSquare compute_graphZ
A




b
B

B
\ No newline at end of file
......@@ -746,6 +746,176 @@ TEST(onnx, model_reshape_output_shape_as_input)
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_log_sum)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_log_sum.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{2.77258872f}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_log_sum_exp)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_log_sum_exp.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{3.77258872f}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_l1)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_l1.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{16}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_l2)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_l2.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{4}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_max)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_max.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{16}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_mean)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_mean.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{1}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_min)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_min.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{1}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_prod)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_prod.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{1}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_sum)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_sum.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{16}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_reduce_sum_square)
{
auto function = onnx_import::import_onnx_function(
file_util::path_join(SERIALIZED_ZOO, "onnx/reduce_sum_square.onnx"));
// input data shape (1, 1, 4, 4)
Inputs inputs{
test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}})
.get_vector()};
// output data shape (1,)
Outputs expected_outputs{test::NDArray<float, 4>({{{{16}}}}).get_vector()};
Outputs outputs{execute(function, inputs, "INTERPRETER")};
EXPECT_TRUE(test::all_close_f(expected_outputs.front(), outputs.front()));
}
TEST(onnx, model_shape)
{
auto function =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment