Add a generated test for SpaceToBatchND (#3637)
author장지섭/동작제어Lab(SR)/Engineer/삼성전자 <jiseob.jang@samsung.com>
Mon, 3 Dec 2018 10:41:46 +0000 (19:41 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 3 Dec 2018 10:41:46 +0000 (19:41 +0900)
This commit adds a generated test for SpaceToBatchND.

Signed-off-by: jiseob.jang <jiseob.jang@samsung.com>
runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp
runtimes/tests/neural_networks_test/generated/examples/space_to_batch_float_1_nnfw.example.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/models/space_to_batch_float_1_nnfw.model.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/specs/V1_1/space_to_batch_float_1_nnfw.mod.py [new file with mode: 0644]

index 63dd6af..7e9afa9 100644 (file)
@@ -2507,6 +2507,20 @@ TEST_F(GeneratedTests, space_to_batch_float_1) {
             space_to_batch_float_1::examples);
 }
 
+namespace space_to_batch_float_1_nnfw {
+std::vector<MixedTypedExample> examples = {
+// Generated space_to_batch_float_1_nnfw test
+#include "generated/examples/space_to_batch_float_1_nnfw.example.cpp"
+};
+// Generated model constructor
+#include "generated/models/space_to_batch_float_1_nnfw.model.cpp"
+} // namespace space_to_batch_float_1_nnfw
+TEST_F(GeneratedTests, space_to_batch_float_1_nnfw) {
+    execute(space_to_batch_float_1_nnfw::CreateModel,
+            space_to_batch_float_1_nnfw::is_ignored,
+            space_to_batch_float_1_nnfw::examples);
+}
+
 namespace space_to_batch_float_2 {
 std::vector<MixedTypedExample> examples = {
 // Generated space_to_batch_float_2 test
diff --git a/runtimes/tests/neural_networks_test/generated/examples/space_to_batch_float_1_nnfw.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/space_to_batch_float_1_nnfw.example.cpp
new file mode 100644 (file)
index 0000000..83a5394
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: space_to_batch_float_1_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, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 35, 36, 37, 38, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80, 81, 82, 83, 84, 95, 96, 97, 98, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 26, 27, 28, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 86, 87, 88, 89, 0,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72, 73, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 110, 111, 112, 113, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {}
+}
+}, // End of an example
diff --git a/runtimes/tests/neural_networks_test/generated/models/space_to_batch_float_1_nnfw.model.cpp b/runtimes/tests/neural_networks_test/generated/models/space_to_batch_float_1_nnfw.model.cpp
new file mode 100644 (file)
index 0000000..e6c2f30
--- /dev/null
@@ -0,0 +1,28 @@
+// Generated file (from: space_to_batch_float_1_nnfw.mod.py). Do not edit
+void CreateModel(Model *model) {
+  OperandType type3(Type::TENSOR_FLOAT32, {12, 3, 3, 5});
+  OperandType type0(Type::TENSOR_FLOAT32, {2, 3, 4, 5});
+  OperandType type2(Type::TENSOR_INT32, {2, 2});
+  OperandType type1(Type::TENSOR_INT32, {2});
+  // Phase 1, operands
+  auto input = model->addOperand(&type0);
+  auto block_size = model->addOperand(&type1);
+  auto paddings = model->addOperand(&type2);
+  auto output = model->addOperand(&type3);
+  // Phase 2, operations
+  static int32_t block_size_init[] = {2, 3};
+  model->setOperandValue(block_size, block_size_init, sizeof(int32_t) * 2);
+  static int32_t paddings_init[] = {1, 2, 3, 2};
+  model->setOperandValue(paddings, paddings_init, sizeof(int32_t) * 4);
+  model->addOperation(ANEURALNETWORKS_SPACE_TO_BATCH_ND, {input, block_size, paddings}, {output});
+  // Phase 3, inputs and outputs
+  model->identifyInputsAndOutputs(
+    {input},
+    {output});
+  assert(model->isValid());
+}
+
+bool is_ignored(int i) {
+  static std::set<int> ignore = {};
+  return ignore.find(i) != ignore.end();
+}
diff --git a/runtimes/tests/neural_networks_test/specs/V1_1/space_to_batch_float_1_nnfw.mod.py b/runtimes/tests/neural_networks_test/specs/V1_1/space_to_batch_float_1_nnfw.mod.py
new file mode 100644 (file)
index 0000000..db0a994
--- /dev/null
@@ -0,0 +1,54 @@
+batch = 2
+rows = 3
+cols = 4
+depth = 5
+block_size_height = 2
+block_size_width = 3
+padding_size_height_top = 1
+padding_size_height_bottom = 2
+padding_size_width_left = 3
+padding_size_width_right = 2
+out_batch = batch * block_size_height * block_size_width
+out_rows = (int)((rows + padding_size_height_top + padding_size_height_bottom) / block_size_height)
+out_cols = (int)((cols + padding_size_width_left + padding_size_width_right) / block_size_width)
+
+input_table = [x for x in range(batch * rows * cols * depth)]
+stride_b_in = rows * cols * depth
+stride_h_in = cols * depth
+stride_w_in = depth
+
+output_table = [0 for x in range(out_batch * out_rows * out_cols * depth)]
+stride_b_out = out_rows * out_cols * depth
+stride_h_out = out_cols * depth
+stride_w_out = depth
+
+for b in range(batch):
+  for h in range(rows + padding_size_height_top + padding_size_height_bottom):
+    for w in range(cols + padding_size_width_left + padding_size_width_right):
+      for d in range(depth):
+        out_d = d;
+        out_h = (int)(h / block_size_height);
+        out_w = (int)(w / block_size_width);
+        out_b = b + ((h % block_size_height) * block_size_width + w % block_size_width) * batch;
+
+        if ((h >= padding_size_height_top) and (h < (rows + padding_size_height_top)) and (w >= padding_size_width_left) and (w < (cols + padding_size_width_left))):
+          output_table[out_b * stride_b_out + out_h * stride_h_out + out_w * stride_w_out + out_d] = input_table[b * stride_b_in + (h - padding_size_height_top) * stride_h_in + (w - padding_size_width_left) * stride_w_in + d];
+
+i1 = Input("input", "TENSOR_FLOAT32", "{%d, %d, %d, %d}" % (batch, rows, cols, depth))
+block = Parameter("block_size", "TENSOR_INT32", "{2}", [block_size_height, block_size_width])
+paddings = Parameter("paddings", "TENSOR_INT32", "{2, 2}", [padding_size_height_top, padding_size_height_bottom, padding_size_width_left, padding_size_width_right])
+output = Output("output", "TENSOR_FLOAT32", "{%d, %d, %d, %d}" % (out_batch, out_rows, out_cols, depth))
+
+model = Model()
+model = model.Operation("SPACE_TO_BATCH_ND", i1, block, paddings).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))