Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / tests / nnapi / specs / Ex / unpack_ex_dynamic_nnfw.mod.py
1 #
2 # Copyright (C) 2018 The Android Open Source Project
3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 # refer to tanh_v1_dynamic.mod.py about the structore
19
20 # This adds reshape as the first op in a model and
21 # returns output of reshape, which is dynamic tensor
22
23 # Sample UnPack model, axis = 0
24
25 import dynamic_tensor
26
27 model = Model()
28
29 model_input_shape = [6, 3, 4]
30
31 axis = Int32Scalar("axis", 1)
32 num_splits = Int32Scalar("num_splits", 3)
33 out1 = Output("output1", "TENSOR_FLOAT32", "{6, 4}")
34 out2 = Output("output2", "TENSOR_FLOAT32", "{6, 4}")
35 out3 = Output("output3", "TENSOR_FLOAT32", "{6, 4}")
36
37 dynamic_layer = dynamic_tensor.DynamicInputGenerator(model, model_input_shape, "TENSOR_FLOAT32")
38
39 test_node_input = dynamic_layer.getTestNodeInput()
40
41 model.Operation("UNPACK_EX", test_node_input, num_splits, axis).To([out1, out2, out3])
42
43 # write UNPACK_EX test. input is `test_input`
44
45 # note output shape is used by expected output's shape
46
47 out1_data = [0.3, 1.0, 2.0, 3.0,
48             4.0, 5.5, 6.3, 7.2,
49             8.22, 9.8, 10.3, 11.0,
50             12.22, 13.2, 14.44, 15.32,
51             16.55, 17.33, 18.1, 19.0,
52             20.32, 21.9, 22.1, 23.22]
53
54 out2_data = [24.22, 25.1, 26.0, 27.12,
55             28.32, 29.11, 30.0, 31.98,
56             32.99, 33.11, 34.1, 35.123,
57             36.21, 37.22, 38.23, 39.76,
58             40.1, 41.43, 42.34, 43.1,
59             44.123, 45.43, 46.1, 47.1]
60
61 out3_data = [48.0, 49.76, 50.0, 51.1,
62             52.22, 53.12, 54.1, 55.5,
63             56.5, 57.4, 58.1, 59.23,
64             60.2, 61.12, 62.11, 63.34,
65             64.11, 65.1, 66.43, 67.1,
66             68.1, 69.34, 70.11, 71.45]
67
68 model_input_data = [0.3, 1.0, 2.0, 3.0,
69                     24.22, 25.1, 26.0, 27.12,
70                     48.0, 49.76, 50.0, 51.1,
71                     4.0, 5.5, 6.3, 7.2,
72                     28.32, 29.11, 30.0, 31.98,
73                     52.22, 53.12, 54.1, 55.5,
74                     8.22, 9.8, 10.3, 11.0,
75                     32.99, 33.11, 34.1, 35.123,
76                     56.5, 57.4, 58.1, 59.23,
77                     12.22, 13.2, 14.44, 15.32,
78                     36.21, 37.22, 38.23, 39.76,
79                     60.2, 61.12, 62.11, 63.34,
80                     16.55, 17.33, 18.1, 19.0,
81                     40.1, 41.43, 42.34, 43.1,
82                     64.11, 65.1, 66.43, 67.1,
83                     20.32, 21.9, 22.1, 23.22,
84                     44.123, 45.43, 46.1, 47.1,
85                     68.1, 69.34, 70.11, 71.45]
86
87 Example(
88   {
89     dynamic_layer.getModelInput() : model_input_data,
90     dynamic_layer.getShapeInput() : model_input_shape,
91
92     out1 : out1_data,
93     out2 : out2_data,
94     out3 : out3_data,
95   })