2 Copyright (c) 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.RNN import rnn_infer
17 from mo.graph.graph import Node, Graph
18 from mo.ops.op import Op
24 def __init__(self, graph: Graph, attrs: dict):
26 'type': 'RNNSequence', # should be never emitted to IR; for debugging purposes
28 'blobs_wrb': False, # input blobs have three separate components W, R and B like in ONNX/LSTM
29 'has_num_directions': False, # if True, output shape has 4 dimensions; 3D otherwise
30 'direction': 'forward',
31 'infer': __class__.infer,
36 'format': None, # format type of input blobs for different frameworks (onnx, tf, mxnet),
38 'activation_alpha': None,
39 'activation_beta': None,
46 super().__init__(graph, mandatory_props, attrs)
49 def supported_attrs():
51 'hidden_size', # number of the elements in hidden cell size
52 'direction', # one of 'forward', 'reverse', or 'bidirectional'
59 # 'input_forget', # Not supported yet
62 def backend_attrs(self):
64 'hidden_size', # number of the elements in hidden cell size
65 'direction', # one of 'forward', 'reverse', or 'bidirectional'
70 ('activations', lambda node: ','.join(node.activations) if node.activations is not None else None),
72 # 'input_forget', # Not supported yet
76 def infer(node: Node):
77 # there are limitations coming from ONNX LSTM definition and normalization rules
78 assert len(node.in_nodes()) >= 3 # X, W and R
79 assert len(node.in_nodes()) <= 7
80 assert len(node.out_nodes()) <= 3
82 rnn_infer(node, [1, 2])