1c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang#
2c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# Copyright (C) 2017 The Android Open Source Project
3c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang#
4c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# Licensed under the Apache License, Version 2.0 (the "License");
5c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# you may not use this file except in compliance with the License.
6c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# You may obtain a copy of the License at
7c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang#
8c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang#      http://www.apache.org/licenses/LICENSE-2.0
9c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang#
10c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# Unless required by applicable law or agreed to in writing, software
11c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# distributed under the License is distributed on an "AS IS" BASIS,
12c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# See the License for the specific language governing permissions and
14c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# limitations under the License.
15c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang#
16c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang
17c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwangmodel = Model()
18c96b526122230f552e5bbb96d4bd0497f50c5c91gfani1 = Input("op1", "TENSOR_FLOAT32", "{1, 3, 3, 2}")
19297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungf1 = Parameter("op2", "TENSOR_FLOAT32", "{1, 2, 2, 4}", [.25, 0, .2, 0, .25, 0, 0, .3, .25, 0, 0, 0, .25, .1, 0, 0])
20297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungb1 = Parameter("op3", "TENSOR_FLOAT32", "{4}", [1, 2, 3, 4])
21c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwangpad0 = Int32Scalar("pad0", 0)
22c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwangact = Int32Scalar("act", 0)
23c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwangstride = Int32Scalar("stride", 1)
24c96b526122230f552e5bbb96d4bd0497f50c5c91gfancm = Int32Scalar("channelMultiplier", 2)
25c96b526122230f552e5bbb96d4bd0497f50c5c91gfanoutput = Output("op4", "TENSOR_FLOAT32", "{1, 2, 2, 4}")
26c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang
27c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwangmodel = model.Operation("DEPTHWISE_CONV_2D",
28c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang                        i1, f1, b1,
29c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang                        pad0, pad0, pad0, pad0,
30c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang                        stride, stride,
31c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang                        cm, act).To(output)
32c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang
33c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# Example 1. Input in operand 0,
34c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwanginput0 = {i1: # input 0
35c96b526122230f552e5bbb96d4bd0497f50c5c91gfan          [10, 21, 10, 22, 10, 23,
36c96b526122230f552e5bbb96d4bd0497f50c5c91gfan           10, 24, 10, 25, 10, 26,
37297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung           10, 27, 10, 28, 10, 29]}
38c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# (i1 (conv) f1) + b1
39c96b526122230f552e5bbb96d4bd0497f50c5c91gfan# filter usage:
40c96b526122230f552e5bbb96d4bd0497f50c5c91gfan#   in_ch1 * f_1  --> output_d1
41c96b526122230f552e5bbb96d4bd0497f50c5c91gfan#   in_ch1 * f_2  --> output_d2
42c96b526122230f552e5bbb96d4bd0497f50c5c91gfan#   in_ch2 * f_3  --> output_d3
43c96b526122230f552e5bbb96d4bd0497f50c5c91gfan#   in_ch3 * f_4  --> output_d4
44c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwangoutput0 = {output: # output 0
45c96b526122230f552e5bbb96d4bd0497f50c5c91gfan           [11, 3, 7.2, 10.6,
46c96b526122230f552e5bbb96d4bd0497f50c5c91gfan            11, 3, 7.4, 10.9,
47c96b526122230f552e5bbb96d4bd0497f50c5c91gfan            11, 3, 7.8, 11.5,
48c96b526122230f552e5bbb96d4bd0497f50c5c91gfan            11, 3, 8.0, 11.8]}
49c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang
50c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwang# Instantiate an example
51c715e9dcaab69a0817fd79ebcfb7011c53ff0c13leozwangExample((input0, output0))
52