Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / tests / nnapi / specs / Ex / pack_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 '''
24 Testing Pack op when the input is dynamic.
25        input3[6, 4]  shape [2]  (value of shape will be [6, 4])
26           |             |
27           +-------------+
28           |
29        Reshape (added by DynamicInputGenerator since it generates its output to be dynamic)
30           |
31           |        input1[6, 4]    input2[6, 4]
32           |             |             |
33           +-------------+-------------+
34           |
35           |
36           | dynamic tensor at compilation time but the shape will be [6, 4] at execution time
37           |
38          Pack
39           |
40         output (dynamic tensor, [6, 3, 4] at execution time)
41 '''
42
43 import dynamic_tensor
44
45 model = Model()
46
47 model_input_shape = [6, 4]
48
49 input1 = Input("input1", "TENSOR_FLOAT32", "{6, 4}")
50 input2 = Input("input2", "TENSOR_FLOAT32", "{6, 4}")
51
52 num = Int32Scalar("num_tensors", 3)
53
54 axis = Int32Scalar("axis", 1)
55
56 dynamic_layer = dynamic_tensor.DynamicInputGenerator(model, model_input_shape, "TENSOR_FLOAT32")
57
58 test_node_input = dynamic_layer.getTestNodeInput()
59 # write PACK_EX test. input is `test_input`
60
61 # note output shape is used by expected output's shape
62 model_output = Output("output", "TENSOR_FLOAT32", "{6, 3, 4}")
63
64 model.Operation("PACK_EX", test_node_input, input1, input2, num, axis).To(model_output)
65
66 model_input_data = [0.3, 1.0, 2.0, 3.0,
67             4.0, 5.5, 6.3, 7.2,
68             8.22, 9.8, 10.3, 11.0,
69             12.22, 13.2, 14.44, 15.32,
70             16.55, 17.33, 18.1, 19.0,
71             20.32, 21.9, 22.1, 23.22]
72
73 input1_data = [24.22, 25.1, 26.0, 27.12,
74             28.32, 29.11, 30.0, 31.98,
75             32.99, 33.11, 34.1, 35.123,
76             36.21, 37.22, 38.23, 39.76,
77             40.1, 41.43, 42.34, 43.1,
78             44.123, 45.43, 46.1, 47.1]
79
80 input2_data = [48.0, 49.76, 50.0, 51.1,
81                     52.22, 53.12, 54.1, 55.5,
82                     56.5, 57.4, 58.1, 59.23,
83                     60.2, 61.12, 62.11, 63.34,
84                     64.11, 65.1, 66.43, 67.1,
85                     68.1, 69.34, 70.11, 71.45]
86
87 model_output_data = [0.3, 1.0, 2.0, 3.0,
88                     24.22, 25.1, 26.0, 27.12,
89                     48.0, 49.76, 50.0, 51.1,
90                     4.0, 5.5, 6.3, 7.2,
91                     28.32, 29.11, 30.0, 31.98,
92                     52.22, 53.12, 54.1, 55.5,
93                     8.22, 9.8, 10.3, 11.0,
94                     32.99, 33.11, 34.1, 35.123,
95                     56.5, 57.4, 58.1, 59.23,
96                     12.22, 13.2, 14.44, 15.32,
97                     36.21, 37.22, 38.23, 39.76,
98                     60.2, 61.12, 62.11, 63.34,
99                     16.55, 17.33, 18.1, 19.0,
100                     40.1, 41.43, 42.34, 43.1,
101                     64.11, 65.1, 66.43, 67.1,
102                     20.32, 21.9, 22.1, 23.22,
103                     44.123, 45.43, 46.1, 47.1,
104                     68.1, 69.34, 70.11, 71.45]
105
106 Example({
107     dynamic_layer.getModelInput() : model_input_data,
108     dynamic_layer.getShapeInput() : model_input_shape,
109     input1 : input1_data,
110     input2 : input2_data,
111
112     model_output: model_output_data,
113 })