[test/layers] Add gru layer testing
authorParichay Kapoor <pk.kapoor@samsung.com>
Wed, 13 Oct 2021 05:38:24 +0000 (14:38 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 13 Oct 2021 12:17:24 +0000 (21:17 +0900)
This patch added gru layer unittest for layer golden tests.

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
packaging/unittest_layers_v2.tar.gz
test/input_gen/genLayerTests.py
test/unittest/layers/unittest_layers_gru.cpp

index 888ac14..ddbc5b5 100644 (file)
Binary files a/packaging/unittest_layers_v2.tar.gz and b/packaging/unittest_layers_v2.tar.gz differ
index d0b1bbf..194a102 100644 (file)
@@ -113,5 +113,28 @@ if __name__ == "__main__":
                          return_state=False)
     record_single(lstm, (3, 4, 7), "lstm_multi_step_seq_act")
 
-inspect_file("lstm_single_step_seq.nnlayergolden")
+    gru = K.layers.GRU(units=5,
+                         recurrent_activation="sigmoid",
+                         activation="tanh",
+                         return_sequences=False,
+                         return_state=False)
+    record_single(gru, (3, 1, 7), "gru_single_step")
+    record_single(gru, (3, 4, 7), "gru_multi_step")
+
+    gru = K.layers.GRU(units=5,
+                         recurrent_activation="sigmoid",
+                         activation="tanh",
+                         return_sequences=True,
+                         return_state=False)
+    record_single(gru, (3, 1, 7), "gru_single_step_seq")
+    record_single(gru, (3, 4, 7), "gru_multi_step_seq", input_type='float')
+
+    gru = K.layers.GRU(units=5,
+                         recurrent_activation="tanh",
+                         activation="sigmoid",
+                         return_sequences=True,
+                         return_state=False)
+    record_single(gru, (3, 4, 7), "gru_multi_step_seq_act")
+
+inspect_file("gru_single_step_seq.nnlayergolden")
 
index 6a838b5..989b77a 100644 (file)
@@ -21,3 +21,42 @@ auto semantic_gru =
                           nntrainer::GRULayer::type, {"unit=1"}, 0, false, 1);
 
 INSTANTIATE_TEST_CASE_P(GRU, LayerSemantics, ::testing::Values(semantic_gru));
+
+auto gru_single_step = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::GRULayer>, {"unit=5"}, "3:1:1:7",
+  "gru_single_step.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto gru_multi_step = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::GRULayer>, {"unit=5"}, "3:1:4:7",
+  "gru_multi_step.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto gru_single_step_seq = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::GRULayer>,
+  {"unit=5", "return_sequences=true"}, "3:1:1:7",
+  "gru_single_step_seq.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto gru_multi_step_seq = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::GRULayer>,
+  {"unit=5", "return_sequences=true"}, "3:1:4:7",
+  "gru_multi_step_seq.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT);
+
+auto gru_multi_step_seq_act_orig = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::GRULayer>,
+  {"unit=5", "return_sequences=true", "hidden_state_activation=tanh",
+   "recurrent_activation=sigmoid"},
+  "3:1:4:7", "gru_multi_step_seq.nnlayergolden",
+  LayerGoldenTestParamOptions::DEFAULT);
+
+auto gru_multi_step_seq_act = LayerGoldenTestParamType(
+  nntrainer::createLayer<nntrainer::GRULayer>,
+  {"unit=5", "return_sequences=true", "hidden_state_activation=sigmoid",
+   "recurrent_activation=tanh"},
+  "3:1:4:7", "gru_multi_step_seq_act.nnlayergolden",
+  LayerGoldenTestParamOptions::DEFAULT);
+
+INSTANTIATE_TEST_CASE_P(GRU, LayerGoldenTest,
+                        ::testing::Values(gru_single_step, gru_multi_step,
+                                          gru_single_step_seq,
+                                          gru_multi_step_seq,
+                                          gru_multi_step_seq_act_orig,
+                                          gru_multi_step_seq_act));