From 7b9803872e05252a777127cd6173c4865cc2c148 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9E=A5=EC=A7=80=EC=84=AD/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Mon, 26 Nov 2018 17:13:44 +0900 Subject: [PATCH] Add generated tests of Mean for 4-D (#3453) This commit Add generated tests of Mean for 4-D. Signed-off-by: jiseob.jang --- .../generated/all_generated_tests.cpp | 28 ++++++++++++++++ .../mean_4D_float_reducing_C_nnfw.example.cpp | 22 ++++++++++++ .../mean_4D_float_reducing_HW_nnfw.example.cpp | 22 ++++++++++++ .../models/mean_4D_float_reducing_C_nnfw.model.cpp | 28 ++++++++++++++++ .../mean_4D_float_reducing_HW_nnfw.model.cpp | 28 ++++++++++++++++ .../V1_1/mean_4D_float_reducing_C_nnfw.mod.py | 39 ++++++++++++++++++++++ .../V1_1/mean_4D_float_reducing_HW_nnfw.mod.py | 39 ++++++++++++++++++++++ 7 files changed, 206 insertions(+) create mode 100644 runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_C_nnfw.example.cpp create mode 100644 runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_HW_nnfw.example.cpp create mode 100644 runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_C_nnfw.model.cpp create mode 100644 runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_HW_nnfw.model.cpp create mode 100644 runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_C_nnfw.mod.py create mode 100644 runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_HW_nnfw.mod.py diff --git a/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp b/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp index 5d5c437..374cd24 100644 --- a/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp +++ b/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp @@ -2283,6 +2283,34 @@ TEST_F(GeneratedTests, fully_connected_float_4d_simple) { fully_connected_float_4d_simple::examples); } +namespace mean_4D_float_reducing_C_nnfw { +std::vector examples = { +// Generated mean_4D_float_reducing_C_nnfw test +#include "generated/examples/mean_4D_float_reducing_C_nnfw.example.cpp" +}; +// Generated model constructor +#include "generated/models/mean_4D_float_reducing_C_nnfw.model.cpp" +} // namespace mean_4D_float_reducing_C_nnfw +TEST_F(GeneratedTests, mean_4D_float_reducing_C_nnfw) { + execute(mean_4D_float_reducing_C_nnfw::CreateModel, + mean_4D_float_reducing_C_nnfw::is_ignored, + mean_4D_float_reducing_C_nnfw::examples); +} + +namespace mean_4D_float_reducing_HW_nnfw { +std::vector examples = { +// Generated mean_4D_float_reducing_HW_nnfw test +#include "generated/examples/mean_4D_float_reducing_HW_nnfw.example.cpp" +}; +// Generated model constructor +#include "generated/models/mean_4D_float_reducing_HW_nnfw.model.cpp" +} // namespace mean_4D_float_reducing_HW_nnfw +TEST_F(GeneratedTests, mean_4D_float_reducing_HW_nnfw) { + execute(mean_4D_float_reducing_HW_nnfw::CreateModel, + mean_4D_float_reducing_HW_nnfw::is_ignored, + mean_4D_float_reducing_HW_nnfw::examples); +} + namespace mean_axis01_1_nnfw { std::vector examples = { // Generated mean_axis01_1_nnfw test diff --git a/runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_C_nnfw.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_C_nnfw.example.cpp new file mode 100644 index 0000000..a9db13f --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_C_nnfw.example.cpp @@ -0,0 +1,22 @@ +// Generated file (from: mean_4D_float_reducing_C_nnfw.mod.py). Do not edit +// Begin of an example +{ +//Input(s) +{ // See tools/test_generator/include/TestHarness.h:MixedTyped + // int -> FLOAT32 map + {{0, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119}}}, + // int -> INT32 map + {}, + // int -> QUANT8_ASYMM map + {} +}, +//Output(s) +{ // See tools/test_generator/include/TestHarness.h:MixedTyped + // int -> FLOAT32 map + {{0, {2.0f, 7.0f, 12.0f, 17.0f, 22.0f, 27.0f, 32.0f, 37.0f, 42.0f, 47.0f, 52.0f, 57.0f, 62.0f, 67.0f, 72.0f, 77.0f, 82.0f, 87.0f, 92.0f, 97.0f, 102.0f, 107.0f, 112.0f, 117.0f}}}, + // int -> INT32 map + {}, + // int -> QUANT8_ASYMM map + {} +} +}, // End of an example diff --git a/runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_HW_nnfw.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_HW_nnfw.example.cpp new file mode 100644 index 0000000..9b08c73 --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/examples/mean_4D_float_reducing_HW_nnfw.example.cpp @@ -0,0 +1,22 @@ +// Generated file (from: mean_4D_float_reducing_HW_nnfw.mod.py). Do not edit +// Begin of an example +{ +//Input(s) +{ // See tools/test_generator/include/TestHarness.h:MixedTyped + // int -> FLOAT32 map + {{0, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119}}}, + // int -> INT32 map + {}, + // int -> QUANT8_ASYMM map + {} +}, +//Output(s) +{ // See tools/test_generator/include/TestHarness.h:MixedTyped + // int -> FLOAT32 map + {{0, {27.5f, 28.5f, 29.5f, 30.5f, 31.5f, 87.5f, 88.5f, 89.5f, 90.5f, 91.5f}}}, + // int -> INT32 map + {}, + // int -> QUANT8_ASYMM map + {} +} +}, // End of an example diff --git a/runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_C_nnfw.model.cpp b/runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_C_nnfw.model.cpp new file mode 100644 index 0000000..3cbf132 --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_C_nnfw.model.cpp @@ -0,0 +1,28 @@ +// Generated file (from: mean_4D_float_reducing_C_nnfw.mod.py). Do not edit +void CreateModel(Model *model) { + OperandType type2(Type::INT32, {}); + OperandType type0(Type::TENSOR_FLOAT32, {2, 3, 4, 5}); + OperandType type3(Type::TENSOR_FLOAT32, {2, 3, 4}); + OperandType type1(Type::TENSOR_INT32, {2}); + // Phase 1, operands + auto input = model->addOperand(&type0); + auto axis = model->addOperand(&type1); + auto keepDims = model->addOperand(&type2); + auto output = model->addOperand(&type3); + // Phase 2, operations + static int32_t axis_init[] = {3, -1}; + model->setOperandValue(axis, axis_init, sizeof(int32_t) * 2); + static int32_t keepDims_init[] = {0}; + model->setOperandValue(keepDims, keepDims_init, sizeof(int32_t) * 1); + model->addOperation(ANEURALNETWORKS_MEAN, {input, axis, keepDims}, {output}); + // Phase 3, inputs and outputs + model->identifyInputsAndOutputs( + {input}, + {output}); + assert(model->isValid()); +} + +bool is_ignored(int i) { + static std::set ignore = {}; + return ignore.find(i) != ignore.end(); +} diff --git a/runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_HW_nnfw.model.cpp b/runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_HW_nnfw.model.cpp new file mode 100644 index 0000000..79fbe81 --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/models/mean_4D_float_reducing_HW_nnfw.model.cpp @@ -0,0 +1,28 @@ +// Generated file (from: mean_4D_float_reducing_HW_nnfw.mod.py). Do not edit +void CreateModel(Model *model) { + OperandType type2(Type::INT32, {}); + OperandType type0(Type::TENSOR_FLOAT32, {2, 3, 4, 5}); + OperandType type3(Type::TENSOR_FLOAT32, {2, 5}); + OperandType type1(Type::TENSOR_INT32, {4}); + // Phase 1, operands + auto input = model->addOperand(&type0); + auto axis = model->addOperand(&type1); + auto keepDims = model->addOperand(&type2); + auto output = model->addOperand(&type3); + // Phase 2, operations + static int32_t axis_init[] = {1, 2, -3, -2}; + model->setOperandValue(axis, axis_init, sizeof(int32_t) * 4); + static int32_t keepDims_init[] = {0}; + model->setOperandValue(keepDims, keepDims_init, sizeof(int32_t) * 1); + model->addOperation(ANEURALNETWORKS_MEAN, {input, axis, keepDims}, {output}); + // Phase 3, inputs and outputs + model->identifyInputsAndOutputs( + {input}, + {output}); + assert(model->isValid()); +} + +bool is_ignored(int i) { + static std::set ignore = {}; + return ignore.find(i) != ignore.end(); +} diff --git a/runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_C_nnfw.mod.py b/runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_C_nnfw.mod.py new file mode 100644 index 0000000..37bc383 --- /dev/null +++ b/runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_C_nnfw.mod.py @@ -0,0 +1,39 @@ +batch = 2 +rows = 3 +cols = 4 +depth = 5 + +input_table = [x for x in range(batch * rows * cols * depth)] +for i in range(batch): + for j in range(rows): + for k in range(cols): + for l in range(depth): + input_table[i * rows * cols * depth + j * cols * depth + k * depth + l] = i * rows * cols * depth + j * cols * depth + k * depth + l; + +output_table = [0 for x in range(batch * rows * cols)] +for i in range(batch): + for j in range(rows): + for k in range(cols): + for l in range(depth): + output_table[i * rows * cols + j * cols + k] += input_table[i * rows * cols * depth + j * cols * depth + k * depth + l]; + +for i in range(batch * rows * cols): + output_table[i] /= float(depth); + +model = Model() +i1 = Input("input", "TENSOR_FLOAT32", "{%d, %d, %d, %d}" % (batch, rows, cols, depth)) +axis = Parameter("axis", "TENSOR_INT32", "{2}", [3, -1]) +keepDims = Int32Scalar("keepDims", 0) +output = Output("output", "TENSOR_FLOAT32", "{%d, %d, %d}" % (batch, rows, cols)) + +model = model.Operation("MEAN", i1, axis, keepDims).To(output) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + input_table} + +output0 = {output: # output 0 + output_table} + +# Instantiate an example +Example((input0, output0)) diff --git a/runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_HW_nnfw.mod.py b/runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_HW_nnfw.mod.py new file mode 100644 index 0000000..a778a65 --- /dev/null +++ b/runtimes/tests/neural_networks_test/specs/V1_1/mean_4D_float_reducing_HW_nnfw.mod.py @@ -0,0 +1,39 @@ +batch = 2 +rows = 3 +cols = 4 +depth = 5 + +input_table = [x for x in range(batch * rows * cols * depth)] +for i in range(batch): + for j in range(rows): + for k in range(cols): + for l in range(depth): + input_table[i * rows * cols * depth + j * cols * depth + k * depth + l] = i * rows * cols * depth + j * cols * depth + k * depth + l; + +output_table = [0 for x in range(batch * depth)] +for i in range(batch): + for j in range(rows): + for k in range(cols): + for l in range(depth): + output_table[i * depth + l] += input_table[i * rows * cols * depth + j * cols * depth + k * depth + l]; + +for i in range(batch * depth): + output_table[i] /= float(rows * cols); + +model = Model() +i1 = Input("input", "TENSOR_FLOAT32", "{%d, %d, %d, %d}" % (batch, rows, cols, depth)) +axis = Parameter("axis", "TENSOR_INT32", "{4}", [1, 2, -3, -2]) +keepDims = Int32Scalar("keepDims", 0) +output = Output("output", "TENSOR_FLOAT32", "{%d, %d}" % (batch, depth)) + +model = model.Operation("MEAN", i1, axis, keepDims).To(output) + +# Example 1. Input in operand 0, +input0 = {i1: # input 0 + input_table} + +output0 = {output: # output 0 + output_table} + +# Instantiate an example +Example((input0, output0)) -- 2.7.4