1#
2# Copyright (C) 2017 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
17batches = 2
18units = 4
19input_size = 3
20memory_size = 10
21
22model = Model()
23
24input = Input("input", "TENSOR_FLOAT32", "{%d, %d}" % (batches, input_size))
25weights_feature = Input("weights_feature", "TENSOR_FLOAT32", "{%d, %d}" % (units, input_size))
26weights_time = Input("weights_time", "TENSOR_FLOAT32", "{%d, %d}" % (units, memory_size))
27bias = Input("bias", "TENSOR_FLOAT32", "{%d}" % (units))
28state_in = Input("state_in", "TENSOR_FLOAT32", "{%d, %d}" % (batches, memory_size*units))
29rank_param = Int32Scalar("rank_param", 1)
30activation_param = Int32Scalar("activation_param", 0)
31state_out = Output("state_out", "TENSOR_FLOAT32", "{%d, %d}" % (batches, memory_size*units))
32output = Output("output", "TENSOR_FLOAT32", "{%d, %d}" % (batches, units))
33
34model = model.Operation("SVDF", input, weights_feature, weights_time, bias, state_in,
35                        rank_param, activation_param).To([state_out, output])
36
37input0 = {
38    weights_feature: [
39        -0.31930989, -0.36118156, 0.0079667, 0.37613347,
40      0.22197971, 0.12416199, 0.27901134, 0.27557442,
41      0.3905206, -0.36137494, -0.06634006, -0.10640851
42    ],
43    weights_time: [
44        -0.31930989, 0.37613347,  0.27901134,  -0.36137494, -0.36118156,
45      0.22197971,  0.27557442,  -0.06634006, 0.0079667,   0.12416199,
46
47       0.3905206,   -0.10640851, -0.0976817,  0.15294972,  0.39635518,
48      -0.02702999, 0.39296314,  0.15785322,  0.21931258,  0.31053296,
49
50       -0.36916667, 0.38031587,  -0.21580373, 0.27072677,  0.23622236,
51      0.34936687,  0.18174365,  0.35907319,  -0.17493086, 0.324846,
52
53       -0.10781813, 0.27201805,  0.14324132,  -0.23681851, -0.27115166,
54      -0.01580888, -0.14943552, 0.15465137,  0.09784451,  -0.0337657
55    ],
56    bias: [],
57}
58
59input0[input] = [
60  0.14278367,  -1.64410412, -0.75222826,
61  0.14278367,  -1.64410412, -0.75222826,
62]
63input0[state_in]  = [
64  0, 0, 0, 0,
65  0, 0, 0, 0,
66  0.119996, 0, 0, 0,
67  0, 0, 0, 0,
68  0, 0, -0.166701, 0,
69  0, 0, 0, 0,
70  0, 0, 0, 0,
71  -0.44244, 0, 0, 0,
72  0, 0, 0, 0,
73  0, 0, 0.0805206, 0,
74  0, 0, 0, 0,
75  0, 0, 0, 0,
76  0.119996, 0, 0, 0,
77  0, 0, 0, 0,
78  0, 0, -0.166701, 0,
79  0, 0, 0, 0,
80  0, 0, 0, 0,
81  -0.44244, 0, 0, 0,
82  0, 0, 0, 0,
83  0, 0, 0.0805206, 0,
84]
85output0 = {
86    state_out : [
87  0, 0, 0, 0,
88  0, 0, 0, 0.119996,
89  0.542235, 0, 0, 0,
90  0, 0, 0, 0,
91  0, -0.166701, -0.40465, 0,
92  0, 0, 0, 0,
93  0, 0, 0, -0.44244,
94  -0.706995, 0, 0, 0,
95  0, 0, 0, 0,
96  0, 0.0805206, 0.137515, 0,
97  0, 0, 0, 0,
98  0, 0, 0, 0.119996,
99  0.542235, 0, 0, 0,
100  0, 0, 0, 0,
101  0, -0.166701, -0.40465, 0,
102  0, 0, 0, 0,
103  0, 0, 0, -0.44244,
104  -0.706995, 0, 0, 0,
105  0, 0, 0, 0,
106  0, 0.0805206, 0.137515, 0,
107    ],
108    output : [
109  0.068281,    -0.162217,  -0.152268, 0.00323521,
110  0.068281,    -0.162217,  -0.152268, 0.00323521,
111    ]
112}
113
114Example((input0, output0))
115