summaryrefslogtreecommitdiff
path: root/tests/nnapi/specs/skip/V1_2/depthwise_conv2d_per_channel.mod.py
blob: 2df79ee345d913d9d7c23f98bf5856cb38a80d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# Copyright (C) 2018 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TEST 1: Same scales, zeroPoint = 0
i1 = Input("op1", "TENSOR_QUANT8_ASYMM", "{1, 2, 2, 2}, 0.5f, 0")
f1 = Parameter("op2", "TENSOR_QUANT8_SYMM_PER_CHANNEL", "{1, 2, 2, 2}, 0.0f, 0",
               [2, 4,  2, 0,  2, 2,  2, 0],
               extraParams = SymmPerChannelQuantParams(channelDim=3, scales=[0.5, 0.5]))
b1 = Parameter("op3", "TENSOR_INT32", "{2}", [0, 0])
o1 = Output("op4", "TENSOR_QUANT8_ASYMM", "{1, 1, 1, 2}, 1.f, 0")
Model("same").Operation("DEPTHWISE_CONV_2D", i1, f1, b1, 0, 0, 0, 0, 1, 1, 1, 0).To(o1)

# Instantiate an example
Example({
    i1: [4, 16, 4, 32, 4, 64, 4, 128],
    o1: [8, 48],
}).AddInput(f1, b1)


# TEST 2: Different scales, zeroPoint=128
i2 = Input("op1", "TENSOR_QUANT8_ASYMM", "{1, 3, 3, 2}, 0.5f, 128")
f2 = Parameter("op2", "TENSOR_QUANT8_SYMM_PER_CHANNEL", "{1, 2, 2, 4}, 0.0f, 0",
               [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
               extraParams = SymmPerChannelQuantParams(channelDim=3, scales=[1.0, 0.5, 1.0, 0.5]))
b2 = Parameter("op3", "TENSOR_INT32", "{4}", [4, 4, 4, 4])
o2 = Output("op4", "TENSOR_QUANT8_ASYMM", "{1, 2, 2, 4}, 1.f, 128")
Model("different").Operation("DEPTHWISE_CONV_2D", i2, f2, b2, 0, 0, 0, 0, 1, 1, 2, 0).To(o2)

# Instantiate an example
Example({
    i2: [129, 130] * 9,
    o2: [132, 130, 134, 131, 132, 130, 134, 131,
         132, 130, 134, 131, 132, 130, 134, 131],
}).AddInput(f2, b2)


layout = BoolScalar("layout", False) # NHWC

# TEST 3: With layout param
i3 = Input("op1", "TENSOR_QUANT8_ASYMM", "{1, 3, 3, 2}, 0.5f, 128")
f3 = Parameter("op2", "TENSOR_QUANT8_SYMM_PER_CHANNEL", "{1, 2, 2, 4}, 0.0f, 0",
               [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
               extraParams = SymmPerChannelQuantParams(channelDim=3, scales=[1.0, 0.5, 1.0, 0.5]))
b3 = Parameter("op3", "TENSOR_INT32", "{4}", [4, 4, 4, 4])
o3 = Output("op4", "TENSOR_QUANT8_ASYMM", "{1, 2, 2, 4}, 1.f, 128")
Model("layout").Operation("DEPTHWISE_CONV_2D", i3, f3, b3, 0, 0, 0, 0, 1, 1, 2, 0, layout).To(o3)

# Instantiate an example
Example({
    i3: [129, 130] * 9,
    o3: [132, 130, 134, 131, 132, 130, 134, 131,
         132, 130, 134, 131, 132, 130, 134, 131],
}).AddNchw(i3, o3, layout).AddInput(f3, b3)