Home | History | Annotate | Download | only in V1_2
      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 
     17 layout = BoolScalar("layout", False) # NHWC
     18 
     19 # TEST 1: dilation set to 1 (default)
     20 i1 = Input("op1", "TENSOR_FLOAT32", "{1, 3, 3, 1}")
     21 f1 = Parameter("op2", "TENSOR_FLOAT32", "{1, 2, 2, 1}", [.25, .25, .25, .25])
     22 b1 = Parameter("op3", "TENSOR_FLOAT32", "{1}", [0])
     23 o1 = Output("op4", "TENSOR_FLOAT32", "{1, 2, 2, 1}")
     24 Model().Operation("CONV_2D", i1, f1, b1, 0, 0, 0, 0, 1, 1, 0, layout, 1, 1).To(o1)
     25 
     26 # Additional data type
     27 quant8 = DataTypeConverter().Identify({
     28     i1: ("TENSOR_QUANT8_ASYMM", 0.5, 0),
     29     f1: ("TENSOR_QUANT8_ASYMM", 0.125, 0),
     30     b1: ("TENSOR_INT32", 0.0625, 0),
     31     o1: ("TENSOR_QUANT8_ASYMM", 0.125, 0)
     32 })
     33 
     34 # Instantiate an example
     35 example = Example({
     36     i1: [1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.0],
     37     o1: [.875, .875, .875, .875]
     38 }).AddNchw(i1, o1, layout).AddInput(f1, b1).AddVariations("relaxed", quant8, "float16")
     39 
     40 
     41 # TEST 2: dilation set to 3
     42 i2 = Input("op1", "TENSOR_FLOAT32", "{1, 9, 9, 1}")
     43 f2 = Parameter("op2", "TENSOR_FLOAT32", "{1, 3, 3, 1}", [1, 2, 3, 4, 5, 6, 7, 8, 9])
     44 b2 = Parameter("op3", "TENSOR_FLOAT32", "{1}", [0])
     45 o2 = Output("op4", "TENSOR_FLOAT32", "{1, 3, 3, 1}")
     46 Model().Operation("CONV_2D", i2, f2, b2, 0, 0, 0, 0, 1, 1, 0, layout, 3, 3).To(o2)
     47 
     48 # Additional data type
     49 quant8 = DataTypeConverter().Identify({
     50     i2: ("TENSOR_QUANT8_ASYMM", 0.5, 0),
     51     f2: ("TENSOR_QUANT8_ASYMM", 0.125, 0),
     52     b2: ("TENSOR_INT32", 0.0625, 0),
     53     o2: ("TENSOR_QUANT8_ASYMM", 0.125, 0)
     54 })
     55 
     56 # Instantiate an example
     57 example = Example({
     58     i2: [0, 0, 0, 0, 0, 0, 0, 0, 0,
     59          0, 0, 0, 0, 0, 0, 0, 0, 0,
     60          0, 0, 0, 0, 0, 0, 0, 0, 0,
     61          0, 0, 0, 1, 1, 1, 0, 0, 0,
     62          0, 0, 0, 1, 1, 1, 0, 0, 0,
     63          0, 0, 0, 1, 1, 1, 0, 0, 0,
     64          0, 0, 0, 0, 0, 0, 0, 0, 0,
     65          0, 0, 0, 0, 0, 0, 0, 0, 0,
     66          0, 0, 0, 0, 0, 0, 0, 0, 0],
     67     o2: [5, 5, 5, 5, 5, 5, 5, 5, 5]
     68 }).AddNchw(i2, o2, layout).AddInput(f2, b2).AddVariations("relaxed", quant8, "float16")
     69 
     70 # TEST 3: same as test 1 but with implicit VALID padding
     71 i1 = Input("op1", "TENSOR_FLOAT32", "{1, 3, 3, 1}")
     72 f1 = Parameter("op2", "TENSOR_FLOAT32", "{1, 2, 2, 1}", [.25, .25, .25, .25])
     73 b1 = Parameter("op3", "TENSOR_FLOAT32", "{1}", [0])
     74 o1 = Output("op4", "TENSOR_FLOAT32", "{1, 2, 2, 1}")
     75 Model().Operation("CONV_2D", i1, f1, b1, 2, 1, 1, 0, layout, 1, 1).To(o1)
     76 
     77 # Additional data type
     78 quant8 = DataTypeConverter().Identify({
     79     i1: ("TENSOR_QUANT8_ASYMM", 0.5, 0),
     80     f1: ("TENSOR_QUANT8_ASYMM", 0.125, 0),
     81     b1: ("TENSOR_INT32", 0.0625, 0),
     82     o1: ("TENSOR_QUANT8_ASYMM", 0.125, 0)
     83 })
     84 
     85 # Instantiate an example
     86 example = Example({
     87     i1: [1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.0],
     88     o1: [.875, .875, .875, .875]
     89 }, name="valid_padding").AddNchw(i1, o1, layout).AddInput(f1, b1).AddVariations("relaxed", quant8, "float16")
     90 
     91 
     92 # TEST 4: same as test 2 but with implicit VALID padding
     93 i2 = Input("op1", "TENSOR_FLOAT32", "{1, 9, 9, 1}")
     94 f2 = Parameter("op2", "TENSOR_FLOAT32", "{1, 3, 3, 1}", [1, 2, 3, 4, 5, 6, 7, 8, 9])
     95 b2 = Parameter("op3", "TENSOR_FLOAT32", "{1}", [0])
     96 o2 = Output("op4", "TENSOR_FLOAT32", "{1, 3, 3, 1}")
     97 Model().Operation("CONV_2D", i2, f2, b2, 2, 1, 1, 0, layout, 3, 3).To(o2)
     98 
     99 # Additional data type
    100 quant8 = DataTypeConverter().Identify({
    101     i2: ("TENSOR_QUANT8_ASYMM", 0.5, 0),
    102     f2: ("TENSOR_QUANT8_ASYMM", 0.125, 0),
    103     b2: ("TENSOR_INT32", 0.0625, 0),
    104     o2: ("TENSOR_QUANT8_ASYMM", 0.125, 0)
    105 })
    106 
    107 # Instantiate an example
    108 example = Example({
    109     i2: [0, 0, 0, 0, 0, 0, 0, 0, 0,
    110          0, 0, 0, 0, 0, 0, 0, 0, 0,
    111          0, 0, 0, 0, 0, 0, 0, 0, 0,
    112          0, 0, 0, 1, 1, 1, 0, 0, 0,
    113          0, 0, 0, 1, 1, 1, 0, 0, 0,
    114          0, 0, 0, 1, 1, 1, 0, 0, 0,
    115          0, 0, 0, 0, 0, 0, 0, 0, 0,
    116          0, 0, 0, 0, 0, 0, 0, 0, 0,
    117          0, 0, 0, 0, 0, 0, 0, 0, 0],
    118     o2: [5, 5, 5, 5, 5, 5, 5, 5, 5]
    119 }, name="valid_padding").AddNchw(i2, o2, layout).AddInput(f2, b2).AddVariations("relaxed", quant8, "float16")
    120 
    121 
    122 # TEST 5: dilation set to 3, SAME padding
    123 i3 = Input("op1", "TENSOR_FLOAT32", "{1, 6, 6, 1}")
    124 f3 = Parameter("op2", "TENSOR_FLOAT32", "{1, 2, 2, 1}", [1, 2, 3, 4])
    125 b3 = Parameter("op3", "TENSOR_FLOAT32", "{1}", [0])
    126 o3 = Output("op4", "TENSOR_FLOAT32", "{1, 3, 3, 1}")
    127 Model().Operation("CONV_2D", i3, f3, b3, 1, 2, 2, 0, layout, 3, 3).To(o3)
    128 
    129 # Additional data type
    130 quant8 = DataTypeConverter().Identify({
    131     i3: ("TENSOR_QUANT8_ASYMM", 0.5, 0),
    132     f3: ("TENSOR_QUANT8_ASYMM", 0.125, 0),
    133     b3: ("TENSOR_INT32", 0.0625, 0),
    134     o3: ("TENSOR_QUANT8_ASYMM", 0.125, 0)
    135 })
    136 
    137 # Instantiate an example
    138 example = Example({
    139     i3: [0, 0, 0, 0, 0, 0,
    140          0, 0, 0, 0, 0, 0,
    141          0, 0, 4, 3, 0, 0,
    142          0, 0, 2, 1, 0, 0,
    143          0, 0, 0, 0, 0, 0,
    144          0, 0, 0, 0, 0, 0],
    145     o3: [16, 0, 9, 0, 0, 0, 4, 0, 1]
    146 }).AddNchw(i3, o3, layout).AddInput(f3, b3).AddVariations("relaxed", quant8, "float16")
    147