1# 2# Copyright (C) 2019 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: DETECTION_POSTPROCESSING 18i1 = Input("scores", "TENSOR_FLOAT32", "{1, 6, 3}") # scores 19i2 = Input("roi", "TENSOR_FLOAT32", "{1, 6, 4}") # roi 20i3 = Input("anchors", "TENSOR_FLOAT32", "{6, 4}") # anchors 21 22o1 = Output("scoresOut", "TENSOR_FLOAT32", "{1, 3}") # scores out 23o2 = Output("roiOut", "TENSOR_FLOAT32", "{1, 3, 4}") # roi out 24o3 = Output("classesOut", "TENSOR_INT32", "{1, 3}") # classes out 25o4 = Output("detectionOut", "TENSOR_INT32", "{1}") # num detections out 26Model("regular").Operation("DETECTION_POSTPROCESSING", i1, i2, i3, 10.0, 10.0, 5.0, 5.0, True, 3, 1, 1, 0.0, 0.5, False).To(o1, o2, o3, o4) 27 28input0 = { 29 i1: [ # class scores - two classes with background 30 0., .9, .8, 31 0., .75, .72, 32 0., .6, .5, 33 0., .93, .95, 34 0., .5, .4, 35 0., .3, .2 36 ], 37 i2: [ # six boxes in center-size encoding 38 0.0, 0.0, 0.0, 0.0, # box #1 39 0.0, 1.0, 0.0, 0.0, # box #2 40 0.0, -1.0, 0.0, 0.0, # box #3 41 0.0, 0.0, 0.0, 0.0, # box #4 42 0.0, 1.0, 0.0, 0.0, # box #5 43 0.0, 0.0, 0.0, 0.0 # box #6 44 ], 45 i3: [ # six anchors in center-size encoding 46 0.5, 0.5, 1.0, 1.0, # anchor #1 47 0.5, 0.5, 1.0, 1.0, # anchor #2 48 0.5, 0.5, 1.0, 1.0, # anchor #3 49 0.5, 10.5, 1.0, 1.0, # anchor #4 50 0.5, 10.5, 1.0, 1.0, # anchor #5 51 0.5, 100.5, 1.0, 1.0 # anchor #6 52 ] 53} 54 55output0 = { 56 o1: [0.95, 0.93, 0.0], 57 o2: [ 58 0.0, 10.0, 1.0, 11.0, 59 0.0, 10.0, 1.0, 11.0, 60 0.0, 0.0, 0.0, 0.0 61 ], 62 o3: [1, 0, 0], 63 o4: [2], 64} 65 66Example((input0, output0)).AddVariations("relaxed", "float16") 67 68# TEST 2: DETECTION_POSTPROCESSING 69i1 = Input("scores", "TENSOR_FLOAT32", "{1, 6, 3}") # scores 70i2 = Input("roi", "TENSOR_FLOAT32", "{1, 6, 4}") # roi 71i3 = Input("anchors", "TENSOR_FLOAT32", "{6, 4}") # anchors 72 73o1 = Output("scoresOut", "TENSOR_FLOAT32", "{1, 3}") # scores out 74o2 = Output("roiOut", "TENSOR_FLOAT32", "{1, 3, 4}") # roi out 75o3 = Output("classesOut", "TENSOR_INT32", "{1, 3}") # classes out 76o4 = Output("detectionOut", "TENSOR_INT32", "{1}") # num detections out 77Model().Operation("DETECTION_POSTPROCESSING", i1, i2, i3, 10.0, 10.0, 5.0, 5.0, False, 3, 1, 1, 0.0, 0.5, False).To(o1, o2, o3, o4) 78 79input0 = { 80 i1: [ # class scores - two classes with background 81 0., .9, .8, 82 0., .75, .72, 83 0., .6, .5, 84 0., .93, .95, 85 0., .5, .4, 86 0., .3, .2 87 ], 88 i2: [ # six boxes in center-size encoding 89 0.0, 0.0, 0.0, 0.0, # box #1 90 0.0, 1.0, 0.0, 0.0, # box #2 91 0.0, -1.0, 0.0, 0.0, # box #3 92 0.0, 0.0, 0.0, 0.0, # box #4 93 0.0, 1.0, 0.0, 0.0, # box #5 94 0.0, 0.0, 0.0, 0.0 # box #6 95 ], 96 i3: [ # six anchors in center-size encoding 97 0.5, 0.5, 1.0, 1.0, # anchor #1 98 0.5, 0.5, 1.0, 1.0, # anchor #2 99 0.5, 0.5, 1.0, 1.0, # anchor #3 100 0.5, 10.5, 1.0, 1.0, # anchor #4 101 0.5, 10.5, 1.0, 1.0, # anchor #5 102 0.5, 100.5, 1.0, 1.0 # anchor #6 103 ] 104} 105 106output0 = { 107 o1: [0.95, 0.9, 0.3], 108 o2: [ 109 0.0, 10.0, 1.0, 11.0, 110 0.0, 0.0, 1.0, 1.0, 111 0.0, 100.0, 1.0, 101.0 112 ], 113 o3: [1, 0, 0], 114 o4: [3], 115} 116 117Example((input0, output0)).AddVariations("relaxed", "float16") 118 119# TEST 3: DETECTION_POSTPROCESSING 120i1 = Input("scores", "TENSOR_FLOAT32", "{1, 6, 3}") # scores 121i2 = Input("roi", "TENSOR_FLOAT32", "{1, 6, 7}") # roi 122i3 = Input("anchors", "TENSOR_FLOAT32", "{6, 4}") # anchors 123 124o1 = Output("scoresOut", "TENSOR_FLOAT32", "{1, 3}") # scores out 125o2 = Output("roiOut", "TENSOR_FLOAT32", "{1, 3, 4}") # roi out 126o3 = Output("classesOut", "TENSOR_INT32", "{1, 3}") # classes out 127o4 = Output("detectionOut", "TENSOR_INT32", "{1}") # num detections out 128Model().Operation("DETECTION_POSTPROCESSING", i1, i2, i3, 10.0, 10.0, 5.0, 5.0, False, 3, 1, 1, 0.0, 0.5, False).To(o1, o2, o3, o4) 129 130input0 = { 131 i1: [ # class scores - two classes with background 132 0., .9, .8, 133 0., .75, .72, 134 0., .6, .5, 135 0., .93, .95, 136 0., .5, .4, 137 0., .3, .2 138 ], 139 i2: [ # six boxes in center-size encoding 140 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #1 141 0.0, 1.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #2 142 0.0, -1.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #3 143 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #4 144 0.0, 1.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #5 145 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 # box #6 146 ], 147 i3: [ # six anchors in center-size encoding 148 0.5, 0.5, 1.0, 1.0, # anchor #1 149 0.5, 0.5, 1.0, 1.0, # anchor #2 150 0.5, 0.5, 1.0, 1.0, # anchor #3 151 0.5, 10.5, 1.0, 1.0, # anchor #4 152 0.5, 10.5, 1.0, 1.0, # anchor #5 153 0.5, 100.5, 1.0, 1.0 # anchor #6 154 ] 155} 156 157output0 = { 158 o1: [0.95, 0.9, 0.3], 159 o2: [ 160 0.0, 10.0, 1.0, 11.0, 161 0.0, 0.0, 1.0, 1.0, 162 0.0, 100.0, 1.0, 101.0 163 ], 164 o3: [1, 0, 0], 165 o4: [3], 166} 167 168Example((input0, output0)).AddVariations("relaxed", "float16") 169 170# TEST 4: DETECTION_POSTPROCESSING 171i1 = Input("scores", "TENSOR_FLOAT32", "{1, 6, 3}") # scores 172i2 = Input("roi", "TENSOR_FLOAT32", "{1, 6, 7}") # roi 173i3 = Input("anchors", "TENSOR_FLOAT32", "{6, 4}") # anchors 174 175o1 = Output("scoresOut", "TENSOR_FLOAT32", "{1, 3}") # scores out 176o2 = Output("roiOut", "TENSOR_FLOAT32", "{1, 3, 4}") # roi out 177o3 = Output("classesOut", "TENSOR_INT32", "{1, 3}") # classes out 178o4 = Output("detectionOut", "TENSOR_INT32", "{1}") # num detections out 179Model().Operation("DETECTION_POSTPROCESSING", i1, i2, i3, 10.0, 10.0, 5.0, 5.0, False, 3, 1, 1, 0.0, 0.5, True).To(o1, o2, o3, o4) 180 181input0 = { 182 i1: [ # class scores - two classes with background 183 0., .9, .8, 184 0., .75, .72, 185 0., .6, .5, 186 0., .93, .95, 187 0., .5, .4, 188 0., .3, .2 189 ], 190 i2: [ # six boxes in center-size encoding 191 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #1 192 0.0, 1.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #2 193 0.0, -1.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #3 194 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #4 195 0.0, 1.0, 0.0, 0.0, 1.0, 2.0, 3.0, # box #5 196 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0 # box #6 197 ], 198 i3: [ # six anchors in center-size encoding 199 0.5, 0.5, 1.0, 1.0, # anchor #1 200 0.5, 0.5, 1.0, 1.0, # anchor #2 201 0.5, 0.5, 1.0, 1.0, # anchor #3 202 0.5, 10.5, 1.0, 1.0, # anchor #4 203 0.5, 10.5, 1.0, 1.0, # anchor #5 204 0.5, 100.5, 1.0, 1.0 # anchor #6 205 ] 206} 207 208output0 = { 209 o1: [0.95, 0.9, 0.3], 210 o2: [ 211 0.0, 10.0, 1.0, 11.0, 212 0.0, 0.0, 1.0, 1.0, 213 0.0, 100.0, 1.0, 101.0 214 ], 215 o3: [2, 1, 1], 216 o4: [3], 217} 218 219Example((input0, output0)).AddVariations("relaxed", "float16") 220