Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / tests / nnapi / specs / skip / V1_2 / mul_v1_2.mod.py
1 #
2 # Copyright (C) 2018 The Android Open Source Project
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 # TEST 1: MUL float16
18 model = Model()
19 i1 = Input("op1", "TENSOR_FLOAT16", "{3}") # a vector of 3 float16s
20 i2 = Input("op2", "TENSOR_FLOAT16", "{3}") # another vector of 3 float16s
21 act = Int32Scalar("act", 0) # an int32_t scalar activation
22 i3 = Output("op3", "TENSOR_FLOAT16", "{3}")
23 model = model.Operation("MUL", i1, i2, act).To(i3)
24 model = model.RelaxedExecution(False)
25
26 # Example 1. Input in operand 0,
27 input0 = {i1: # input 0
28           [1.0009765625, 1.0, 2.5],
29           i2: # input 1
30           [2, 0.0001, 3.5]}
31
32 output0 = {i3: # output 0
33            [2.001953125, 0.0001000165, 8.75]}
34
35 # Instantiate an example
36 Example((input0, output0))
37
38
39 # TEST 2: MUL broadcast float16
40 model = Model()
41 i1 = Input("op1", "TENSOR_FLOAT16", "{1, 2}")
42 i2 = Input("op2", "TENSOR_FLOAT16", "{2, 2}")
43 act = Int32Scalar("act", 0)
44 i3 = Output("op3", "TENSOR_FLOAT16", "{2, 2}")
45 model = model.Operation("MUL", i1, i2, act).To(i3)
46
47 # Example 1. Input in operand 0,
48 input0 = {i1: # input 0
49           [1, 2],
50           i2: # input 1
51           [1, 2, 3, 4]}
52
53 output0 = {i3: # output 0
54            [1, 4, 3, 8]}
55
56 # Instantiate an example
57 Example((input0, output0))
58
59
60 # TEST 3: MUL, zero-sized input
61
62 # Use BOX_WITH_NMS_LIMIT op to generate a zero-sized internal tensor for box cooridnates.
63 p1 = Parameter("scores", "TENSOR_FLOAT32", "{1, 2}", [0.90, 0.10]) # scores
64 p2 = Parameter("roi", "TENSOR_FLOAT32", "{1, 8}", [1, 1, 10, 10, 0, 0, 10, 10]) # roi
65 o1 = Output("scoresOut", "TENSOR_FLOAT32", "{0}") # scores out
66 o2 = Output("classesOut", "TENSOR_INT32", "{0}") # classes out
67 tmp1 = Internal("roiOut", "TENSOR_FLOAT32", "{0, 4}") # roi out
68 tmp2 = Internal("batchSplitOut", "TENSOR_INT32", "{0}") # batch split out
69 model = Model("zero_sized").Operation("BOX_WITH_NMS_LIMIT", p1, p2, [0], 0.3,  -1, 0, 0.4, 1.0, 0.3).To(o1, tmp1, o2, tmp2)
70
71 # Use ROI_ALIGN op to convert into zero-sized feature map.
72 layout = BoolScalar("layout", False) # NHWC
73 i1 = Input("in", "TENSOR_FLOAT32", "{1, 1, 1, 2}")
74 zero_sized = Internal("featureMap", "TENSOR_FLOAT32", "{0, 2, 2, 2}")
75 model = model.Operation("ROI_ALIGN", i1, tmp1, tmp2, 2, 2, 2.0, 2.0, 4, 4, layout).To(zero_sized)
76
77 # MUL op with numBatches = 0.
78 i2 = Parameter("op", "TENSOR_FLOAT32", "{1, 2, 2, 1}", [1, 2, 3, 4]) # weights
79 o3 = Output("out", "TENSOR_FLOAT32", "{0, 2, 2, 2}") # out
80 model = model.Operation("MUL", zero_sized, i2, 0).To(o3)
81
82 quant8 = DataTypeConverter().Identify({
83     p1: ("TENSOR_QUANT8_ASYMM", 0.1, 128),
84     p2: ("TENSOR_QUANT16_ASYMM", 0.125, 0),
85     o1: ("TENSOR_QUANT8_ASYMM", 0.1, 128),
86     tmp1: ("TENSOR_QUANT16_ASYMM", 0.125, 0),
87     i1: ("TENSOR_QUANT8_ASYMM", 0.1, 128),
88     zero_sized: ("TENSOR_QUANT8_ASYMM", 0.1, 128),
89     i2: ("TENSOR_QUANT8_ASYMM", 0.1, 128),
90     o3: ("TENSOR_QUANT8_ASYMM", 0.1, 128)
91 })
92
93 # Create test case with dummy values.
94 Example({
95     i1: [1, 2],
96     o1: [0],
97     o2: [0],
98     o3: [0],
99 }).AddVariations("relaxed", quant8, "float16")