2 # Copyright (C) 2018 The Android Open Source Project
3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # refer to tanh_v1_dynamic.mod.py about the structore
20 # This adds reshape as the first op in a model and
21 # returns output of reshape, which is dynamic tensor
24 Testing Pack op when the input is dynamic.
25 input3[6, 4] shape [2] (value of shape will be [6, 4])
29 Reshape (added by DynamicInputGenerator since it generates its output to be dynamic)
31 | input1[6, 4] input2[6, 4]
33 +-------------+-------------+
36 | dynamic tensor at compilation time but the shape will be [6, 4] at execution time
40 output (dynamic tensor, [6, 3, 4] at execution time)
47 model_input_shape = [6, 4]
49 input1 = Input("input1", "TENSOR_FLOAT32", "{6, 4}")
50 input2 = Input("input2", "TENSOR_FLOAT32", "{6, 4}")
52 num = Int32Scalar("num_tensors", 3)
54 axis = Int32Scalar("axis", 1)
56 dynamic_layer = dynamic_tensor.DynamicInputGenerator(model, model_input_shape, "TENSOR_FLOAT32")
58 test_node_input = dynamic_layer.getTestNodeInput()
59 # write PACK_EX test. input is `test_input`
61 # note output shape is used by expected output's shape
62 model_output = Output("output", "TENSOR_FLOAT32", "{6, 3, 4}")
64 model.Operation("PACK_EX", test_node_input, input1, input2, num, axis).To(model_output)
66 model_input_data = [0.3, 1.0, 2.0, 3.0,
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]
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]
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]
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,
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]
107 dynamic_layer.getModelInput() : model_input_data,
108 dynamic_layer.getShapeInput() : model_input_shape,
109 input1 : input1_data,
110 input2 : input2_data,
112 model_output: model_output_data,