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.
20 values = list(np.linspace(-10, 10, num_values))
22 for input_type in ["TENSOR_FLOAT32", "TENSOR_FLOAT16"]:
23 for scale, offset in [(1.0, 0),
27 input0 = Input("input0", input_type, "{%d}" % num_values)
28 output0 = Output("output0", input_type, "{%d}" % num_values)
30 model = Model().Operation("QUANTIZE", input0).To(output0)
32 quantizeOutput = DataTypeConverter().Identify({
33 output0: ["TENSOR_QUANT8_ASYMM", scale, offset],
39 }).AddVariations(quantizeOutput, includeDefault=False)
44 # Use BOX_WITH_NMS_LIMIT op to generate a zero-sized internal tensor for box cooridnates.
45 p1 = Parameter("scores", "TENSOR_FLOAT32", "{1, 2}", [0.90, 0.10]) # scores
46 p2 = Parameter("roi", "TENSOR_FLOAT32", "{1, 8}", [1, 1, 10, 10, 0, 0, 10, 10]) # roi
47 o1 = Output("scoresOut", "TENSOR_FLOAT32", "{0}") # scores out
48 o2 = Output("classesOut", "TENSOR_INT32", "{0}") # classes out
49 tmp1 = Internal("roiOut", "TENSOR_FLOAT32", "{0, 4}") # roi out
50 tmp2 = Internal("batchSplitOut", "TENSOR_INT32", "{0}") # batch split out
51 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)
53 # Use ROI_ALIGN op to convert into zero-sized feature map.
54 layout = BoolScalar("layout", False) # NHWC
55 i1 = Input("in", "TENSOR_FLOAT32", "{1, 1, 1, 1}")
56 zero_sized = Internal("featureMap", "TENSOR_FLOAT32", "{0, 2, 2, 1}")
57 model = model.Operation("ROI_ALIGN", i1, tmp1, tmp2, 2, 2, 2.0, 2.0, 4, 4, layout).To(zero_sized)
59 # QUANTIZE op with numBatches = 0.
60 o3 = Output("out", "TENSOR_QUANT8_ASYMM", "{0, 2, 2, 1}, 0.1f, 128") # out
61 model = model.Operation("QUANTIZE", zero_sized).To(o3)
63 # Create test case with dummy values.
69 }).AddVariations("relaxed", "float16")