Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / tests / nnapi / specs / V1_2 / log_softmax_nnfw.mod.py
1 #
2 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 # Copyright (C) 2018 The Android Open Source Project
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 # Derived from tensorflow/lite/kernels/activations_test.cc
19
20 def test(input0, output0, input_data, beta, axis, output_data):
21   model = Model().Operation("LOG_SOFTMAX", input0, beta, axis).To(output0)
22   Example({
23       input0: input_data,
24       output0: output_data,
25   }, model=model).AddVariations("relaxed", "float16")
26
27 test(
28     input0=Input("input0", "TENSOR_FLOAT32", "{1, 1, 2, 4}"),
29     output0=Output("output0", "TENSOR_FLOAT32", "{1, 1, 2, 4}"),
30     input_data=[0, -6, 2, 4,
31                 3, -2, 10, 1],
32     beta=1.0,
33     axis=3,
34     output_data=[-4.14297, -10.14297, -2.14297, -.142971,
35                  -7.00104, -12.00104, -.00104087, -9.00104],
36 )
37
38 test(
39     input0=Input("input0", "TENSOR_FLOAT32", "{1, 1, 4, 2}"),
40     output0=Output("output0", "TENSOR_FLOAT32", "{1, 1, 4, 2}"),
41     input_data=[0, -6,
42                 2, 4,
43                 3, -2,
44                 10, 1],
45     beta=1.0,
46     axis=-1,
47     output_data=[-.00247565, -6.00247,
48                  -2.12692, -.126928,
49                  -.00671534, -5.00671,
50                  -.000123374, -9.00012],
51 )
52
53 test(
54     input0=Input("input0", "TENSOR_FLOAT32", "{1, 2, 4, 1}"),
55     output0=Output("output0", "TENSOR_FLOAT32", "{1, 2, 4, 1}"),
56     input_data=[0, 2, 3, 10,
57                 -6, 4, -2, 1],
58     beta=1.0,
59     axis=-3,
60     output_data=[-.00247565, -2.12692, -.00671534, -.000123374,
61                  -6.00247, -.126928, -5.00671, -9.00012],
62 )
63
64 test(
65     input0=Input("input0", "TENSOR_FLOAT32", "{1, 1, 2, 4}"),
66     output0=Output("output0", "TENSOR_FLOAT32", "{1, 1, 2, 4}"),
67     input_data=[0, -.6, .2, .4,
68                 .3, -.2, 1, .1],
69     beta=10.0,
70     axis=3,
71     output_data=[-4.14297, -10.14297, -2.14297, -.142971,
72                  -7.00104, -12.00104, -.00104087, -9.00104],
73 )
74
75 def quant8_test(input0, output0, input_data, beta, axis, output_data):
76   model = Model().Operation("LOG_SOFTMAX", input0, beta, axis).To(output0)
77   quant8 = DataTypeConverter().Identify({
78     input0: ["TENSOR_QUANT8_ASYMM", 10 / 255.0],
79     output0: ["TENSOR_QUANT8_ASYMM", 16 / 256.0, 255],
80   })
81
82   Example({
83       input0: input_data,
84       output0: output_data,
85   }, model=model).AddVariations(quant8)
86
87 quant8_test(
88     input0=Input("input0", "TENSOR_FLOAT32", "{1, 1, 2, 4}"),
89     output0=Output("output0", "TENSOR_FLOAT32", "{1, 1, 2, 4}"),
90     input_data=[0, 6, 2, 4,
91                 3, 2, 10, 1],
92     beta=1.0,
93     axis=3,
94     output_data=[-6.145078, -.145078, -4.145078, -2.145078,
95                  -7.001370, -8.001370, -.001370, -9.001370],
96 )