119d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen#
219d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# Copyright (C) 2017 The Android Open Source Project
319d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen#
419d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# Licensed under the Apache License, Version 2.0 (the "License");
519d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# you may not use this file except in compliance with the License.
619d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# You may obtain a copy of the License at
719d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen#
819d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen#      http://www.apache.org/licenses/LICENSE-2.0
919d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen#
1019d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# Unless required by applicable law or agreed to in writing, software
1119d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# distributed under the License is distributed on an "AS IS" BASIS,
1219d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1319d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# See the License for the specific language governing permissions and
1419d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# limitations under the License.
1519d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen#
1619d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
1719d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# model
1819d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenmodel = Model()
1919d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
2019d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenbat = 1
2119d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenrow = 100
2219d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chencol = 100
2319d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenchn = 1
2419d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
2519d9a2b88298b92548f84b7faff3a113eb1e6462Dong Cheni0 = Input("i0", "TENSOR_QUANT8_ASYMM", "{%d, %d, %d, %d}, 0.5f, 0" % (bat, row, col, chn))
2619d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
2719d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenstd = 4
2819d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenflt = 10
2919d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenpad = 0
3019d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
3119d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenstride = Int32Scalar("stride", std)
3219d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenfilt = Int32Scalar("filter", flt)
3319d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenpadding = Int32Scalar("padding", pad)
3419d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenact0 = Int32Scalar("activation", 0)
3519d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenoutput_row = (row + 2 * pad - flt + std) // std
3619d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenoutput_col = (col + 2 * pad - flt + std) // std
3719d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
3819d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenoutput = Output("output", "TENSOR_QUANT8_ASYMM",
3919d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen                "{%d, %d, %d, %d}, 0.5f, 0" % (bat, output_row, output_col, chn))
4019d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
4119d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenmodel = model.Operation(
4219d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen    "AVERAGE_POOL_2D", i0, padding, padding, padding, padding, stride, stride, filt, filt, act0).To(output)
4319d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
4419d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# Example 1. Input in operand 0,
4519d9a2b88298b92548f84b7faff3a113eb1e6462Dong Cheninput_values = [x % 4 * 2 for x in range(bat * row * col * chn)]
4619d9a2b88298b92548f84b7faff3a113eb1e6462Dong Cheninput0 = {i0: input_values}
4719d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenoutput_values = [3 for _ in range(bat * output_row * output_col * chn)]
4819d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chenoutput0 = {output: output_values}
4919d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen
5019d9a2b88298b92548f84b7faff3a113eb1e6462Dong Chen# Instantiate an example
5119d9a2b88298b92548f84b7faff3a113eb1e6462Dong ChenExample((input0, output0))
52