1b2e34b735db694efd1b32609beffa2a74258789dleozwang# 2b2e34b735db694efd1b32609beffa2a74258789dleozwang# Copyright (C) 2017 The Android Open Source Project 3b2e34b735db694efd1b32609beffa2a74258789dleozwang# 4b2e34b735db694efd1b32609beffa2a74258789dleozwang# Licensed under the Apache License, Version 2.0 (the "License"); 5b2e34b735db694efd1b32609beffa2a74258789dleozwang# you may not use this file except in compliance with the License. 6b2e34b735db694efd1b32609beffa2a74258789dleozwang# You may obtain a copy of the License at 7b2e34b735db694efd1b32609beffa2a74258789dleozwang# 8b2e34b735db694efd1b32609beffa2a74258789dleozwang# http://www.apache.org/licenses/LICENSE-2.0 9b2e34b735db694efd1b32609beffa2a74258789dleozwang# 10b2e34b735db694efd1b32609beffa2a74258789dleozwang# Unless required by applicable law or agreed to in writing, software 11b2e34b735db694efd1b32609beffa2a74258789dleozwang# distributed under the License is distributed on an "AS IS" BASIS, 12b2e34b735db694efd1b32609beffa2a74258789dleozwang# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b2e34b735db694efd1b32609beffa2a74258789dleozwang# See the License for the specific language governing permissions and 14b2e34b735db694efd1b32609beffa2a74258789dleozwang# limitations under the License. 15b2e34b735db694efd1b32609beffa2a74258789dleozwang# 16b2e34b735db694efd1b32609beffa2a74258789dleozwang 17ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanmodel = Model() 18ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfani1 = Input("op1", "TENSOR_FLOAT32", "{1, 3, 3, 1}") 19297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungf1 = Parameter("op2", "TENSOR_FLOAT32", "{1, 2, 2, 1}", [.25, .25, .25, .25]) 20297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sungb1 = Parameter("op3", "TENSOR_FLOAT32", "{1}", [0]) 21ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanpad0 = Int32Scalar("pad0", 0) 22ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanact = Int32Scalar("act", 0) 23ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanstride = Int32Scalar("stride", 1) 24ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan# output dimension: 25ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan# (i1.height - f1.height + 1) x (i1.width - f1.width + 1) 26ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanoutput = Output("op4", "TENSOR_FLOAT32", "{1, 2, 2, 1}") 27ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan 28ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanmodel = model.Operation("CONV_2D", i1, f1, b1, pad0, pad0, pad0, pad0, stride, stride, act).To(output) 29ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan 30ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan# Example 1. Input in operand 0, 31ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfaninput0 = {i1: # input 0 32297c580a2d2da2839d936437bf4e3a4c64034950I-Jui (Ray) Sung [1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 1.0, 1.0, 1.0]} 33ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan 34ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanoutput0 = {output: # output 0 35ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan [.875, .875, .875, .875]} 36ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan 37ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfan# Instantiate an example 38ca5f11deb6d1ae8e8d8b5bd7586b801c0d2654fbgfanExample((input0, output0)) 39