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
23 # Sample UnPack model, axis = 0
29 model_input_shape = [6, 3, 4]
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}")
37 dynamic_layer = dynamic_tensor.DynamicInputGenerator(model, model_input_shape, "TENSOR_FLOAT32")
39 test_node_input = dynamic_layer.getTestNodeInput()
41 model.Operation("UNPACK_EX", test_node_input, num_splits, axis).To([out1, out2, out3])
43 # write UNPACK_EX test. input is `test_input`
45 # note output shape is used by expected output's shape
47 out1_data = [0.3, 1.0, 2.0, 3.0,
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]
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]
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]
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,
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]
89 dynamic_layer.getModelInput() : model_input_data,
90 dynamic_layer.getShapeInput() : model_input_shape,