2 Copyright (c) 2018-2019 Intel Corporation
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
16 from extensions.ops.lstm_cell import LSTMCell
17 from mo.front.caffe.extractors.utils import embed_input
18 from mo.front.extractor import FrontExtractorOp
19 from mo.front.kaldi.loader.utils import collect_until_token, collect_until_whitespace, get_uint32
20 from mo.front.kaldi.utils import read_binary_matrix, read_binary_vector
23 class LSTMProjectedStreamsFrontExtractor(FrontExtractorOp):
24 op = 'lstmprojectedstreams'
31 res = collect_until_whitespace(pb)
32 if res == b'<CellClip>':
33 clip_value = get_uint32(pb.read(4))
34 collect_until_token(pb, b'FM')
35 gifo_x_weights, gifo_x_weights_shape = read_binary_matrix(pb, False)
36 gifo_r_weights, gifo_r_weights_shape = read_binary_matrix(pb)
37 gifo_biases = read_binary_vector(pb)
38 input_gate_weights = read_binary_vector(pb)
39 forget_gate_weights = read_binary_vector(pb)
40 output_gate_weights = read_binary_vector(pb)
42 projection_weights, projection_weights_shape = read_binary_matrix(pb)
44 mapping_rule = {'gifo_x_weights_shape': gifo_x_weights_shape,
45 'gifo_r_weights_shape': gifo_r_weights_shape,
46 'projection_weights_shape': projection_weights_shape,
47 'clip_value': clip_value
50 embed_input(mapping_rule, 1, 'gifo_x_weights', gifo_x_weights)
51 embed_input(mapping_rule, 2, 'gifo_r_weights', gifo_r_weights)
52 embed_input(mapping_rule, 3, 'gifo_biases', gifo_biases)
53 embed_input(mapping_rule, 4, 'input_gate_weights', input_gate_weights)
54 embed_input(mapping_rule, 5, 'forget_gate_weights', forget_gate_weights)
55 embed_input(mapping_rule, 6, 'output_gate_weights', output_gate_weights)
56 embed_input(mapping_rule, 7, 'projection_weights', projection_weights)
58 LSTMCell.update_node_stat(node, mapping_rule)
59 return __class__.enabled
62 class LSTMProjectedFrontExtractor(FrontExtractorOp):
68 return LSTMProjectedStreamsFrontExtractor.extract(node)