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 17layout = BoolScalar("layout", False) # NHWC 18 19# TEST 1: SPACE_TO_BATCH_NCHW_1, block_size = [2, 2] 20i1 = Input("op1", "TENSOR_FLOAT32", "{1, 2, 2, 2}") 21pad1 = Parameter("paddings", "TENSOR_INT32", "{2, 2}", [0, 0, 0, 0]) 22o1 = Output("op4", "TENSOR_FLOAT32", "{4, 1, 1, 2}") 23Model().Operation("SPACE_TO_BATCH_ND", i1, [2, 2], pad1, layout).To(o1) 24 25# Additional data type 26quant8 = DataTypeConverter().Identify({ 27 i1: ("TENSOR_QUANT8_ASYMM", 0.1, 0), 28 o1: ("TENSOR_QUANT8_ASYMM", 0.1, 0) 29}) 30 31# Instantiate an example 32example = Example({ 33 i1: [1.4, 2.3, 3.2, 4.1, 5.4, 6.3, 7.2, 8.1], 34 o1: [1.4, 2.3, 3.2, 4.1, 5.4, 6.3, 7.2, 8.1] 35}).AddNchw(i1, o1, layout).AddVariations("relaxed", "float16", quant8) 36 37 38# TEST 2: SPACE_TO_BATCH_NCHW_2, block_size = [2, 2] 39i2 = Input("op1", "TENSOR_FLOAT32", "{1, 4, 4, 1}") 40o2 = Output("op4", "TENSOR_FLOAT32", "{4, 2, 2, 1}") 41Model().Operation("SPACE_TO_BATCH_ND", i2, [2, 2], pad1, layout).To(o2) 42 43# Additional data type 44quant8 = DataTypeConverter().Identify({ 45 i2: ("TENSOR_QUANT8_ASYMM", 0.5, 0), 46 o2: ("TENSOR_QUANT8_ASYMM", 0.5, 0) 47}) 48 49# Instantiate an example 50example = Example({ 51 i2: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 52 o2: [1, 3, 9, 11, 2, 4, 10, 12, 5, 7, 13, 15, 6, 8, 14, 16] 53}).AddNchw(i2, o2, layout).AddVariations("relaxed", "float16", quant8) 54 55 56# TEST 3: SPACE_TO_BATCH_NCHW_3, block_size = [3, 2] 57i3 = Input("op1", "TENSOR_FLOAT32", "{1, 5, 2, 1}") 58pad3 = Parameter("paddings", "TENSOR_INT32", "{2, 2}", [1, 0, 2, 0]) 59o3 = Output("op4", "TENSOR_FLOAT32", "{6, 2, 2, 1}") 60Model().Operation("SPACE_TO_BATCH_ND", i3, [3, 2], pad3, layout).To(o3) 61 62# Additional data type 63quant8 = DataTypeConverter().Identify({ 64 i3: ("TENSOR_QUANT8_ASYMM", 0.5, 128), 65 o3: ("TENSOR_QUANT8_ASYMM", 0.5, 128) 66}) 67 68# Instantiate an example 69example = Example({ 70 i3: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 71 o3: [0, 0, 0, 5, 0, 0, 0, 6, 0, 1, 0, 7, 72 0, 2, 0, 8, 0, 3, 0, 9, 0, 4, 0, 10] 73}).AddNchw(i3, o3, layout).AddVariations("relaxed", "float16", quant8) 74 75 76# TEST 4: SPACE_TO_BATCH_NCHW_4, block_size = [3, 2] 77i4 = Input("op1", "TENSOR_FLOAT32", "{1, 4, 2, 1}") 78pad4 = Parameter("paddings", "TENSOR_INT32", "{2, 2}", [1, 1, 2, 4]) 79o4 = Output("op4", "TENSOR_FLOAT32", "{6, 2, 4, 1}") 80Model().Operation("SPACE_TO_BATCH_ND", i4, [3, 2], pad4, layout).To(o4) 81 82# Additional data type 83quant8 = DataTypeConverter().Identify({ 84 i4: ("TENSOR_QUANT8_ASYMM", 0.25, 128), 85 o4: ("TENSOR_QUANT8_ASYMM", 0.25, 128) 86}) 87 88# Instantiate an example 89example = Example({ 90 i4: [1, 2, 3, 4, 5, 6, 7, 8], 91 o4: [0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 92 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 93 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0] 94}).AddNchw(i4, o4, layout).AddVariations("relaxed", "float16", quant8) 95