2 # Copyright (C) 2018 The Android Open Source Project
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
22 input0 = Input("input0", "TENSOR_FLOAT32", "{1, 2, 2, 1}")
23 input1 = Input("input1", "TENSOR_FLOAT32", "{1, 2, 2, 1}")
24 activation = Int32Scalar("act", 0)
25 output0 = Output("output0", "TENSOR_FLOAT32", "{1, 2, 2, 1}")
27 model = Model().Operation("SUB", input0, input1, activation).To(output0)
30 input0: [2.0, -4.0, 8.0, -16.0],
31 input1: [2.0, -2.0, -4.0, 4.0],
32 output0: [0.0, -2.0, 12.0, -20.0],
33 }).AddVariations("float16").AddAllActivations(output0, activation)
37 shape = "{2, 4, 16, 2}, 0.5, 0"
38 input0 = Input("input0", "TENSOR_QUANT8_ASYMM", shape)
39 input1 = Input("input1", "TENSOR_QUANT8_ASYMM", shape)
41 output0 = Output("output0", "TENSOR_QUANT8_ASYMM", shape)
43 model = Model("quant8").Operation("SUB", input0, input1, activation).To(output0)
45 input0_values = list(range(256))
46 input1_values = list(input0_values)
47 random.shuffle(input1_values)
48 output_values = [max(0, a - b) for a, b in zip(input0_values, input1_values)]
51 input0: input0_values,
52 input1: input1_values,
53 output0: output_values,
56 # SUB of data type TENSOR_FLOAT32 is introduced in V1_1.
57 Example.SetVersion("V1_1", "sub_v1_2_none", "sub_v1_2_relu", "sub_v1_2_relu1", "sub_v1_2_relu6")
60 # SUB, zero-sized input
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)
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)
77 # SUB 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("SUB", zero_sized, i2, 0).To(o3)
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)
93 # Create test case with dummy values.
99 }).AddVariations("relaxed", quant8, "float16")