Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / tests / nnapi / specs / V1_2 / reduce_mean_dynamic_1_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 '''
19 Testing (Reduce)Mean op when the input is dynamic.
20     input[1, 3, 4, 1] shape [4]
21           |             |
22           +-------------+
23           |
24        Reshape (added by DynamicInputGenerator since it generates its output to be dynamic)
25           |
26           |        axis = 2    keepDims = True
27           |             |             |
28           +-------------+-------------+
29           |
30           |
31           | dynamic tensor at compilation time but the shape will be [1, 3, 4, 1] at execution time
32           |
33       ReduceMean
34           |
35         output (dynamic tensor, [1, 3, 1, 1] at execution time)
36 '''
37
38 import dynamic_tensor
39
40 model = Model()
41
42 model_input_shape = [1, 3, 4, 1]
43
44 dynamic_layer = dynamic_tensor.DynamicInputGenerator(model, model_input_shape, "TENSOR_FLOAT32")
45 test_node_input = dynamic_layer.getTestNodeInput()
46
47 # write REDUCE_MEAN test. input is `test_input`
48
49 # note output shape is used by expected output's shape
50 model_output = Output("output", "TENSOR_FLOAT32", "{1, 3, 1, 1}")
51
52 axis = Int32Scalar("axis", 2)
53 keepDims = Int32Scalar("keepDims", 1)
54
55 model.Operation("MEAN", test_node_input, axis, keepDims).To(model_output)
56
57 model_input_data = [1.0, 2.0, 3.0, 4.0,
58                     1.0, 2.0, 3.0, 4.0,
59                     1.0, 2.0, 3.0, 4.0]
60
61 model_output_data = [2.5, 2.5, 2.5]
62
63 Example({
64     dynamic_layer.getModelInput() : model_input_data,
65     dynamic_layer.getShapeInput() : model_input_shape,
66
67     model_output: model_output_data,
68 })