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 mo.front.common.partial_infer.utils import mark_input_bins
17 from mo.graph.graph import Node, Graph
18 from mo.ops.op import Op
19 from mo.utils.error import Error
23 """ A single GRU cell (without a loop).
26 - [0, required] input data (2D),
27 - [1, required] initial hidden state (2D),
30 - [2, required] cell FC weights
31 - [3, required] cell FC biases
34 - [required] output data / resulting hidden state (2D)
38 def __init__(self, graph: Graph, attrs: dict):
42 'infer': __class__.infer,
46 super().__init__(graph, mandatory_props, attrs)
48 def supported_attrs(self):
50 'hidden_size', # number of the elements in hidden cell size
55 'linear_before_reset',
58 def backend_attrs(self):
60 'hidden_size', # number of the elements in hidden cell size
61 ('activations', lambda node: ','.join(node.activations) if node.activations is not None else None),
65 'linear_before_reset',
69 def infer(node: Node):
70 assert len(node.out_nodes()) in [1, 2]
72 hidden_shape = node.in_node(1).shape.copy()
74 mark_input_bins(node, start_port=2)
75 node.out_node(0).shape = hidden_shape
77 hidden_size = hidden_shape[1]
78 if node.has_valid('hidden_size'):
79 if node.hidden_size != hidden_size:
80 raise Error("Input shape {} for hidden size doesn't match pre-defined hidden_size in node {}".format(
81 node.in_node(1).shape, node.soft_get('name')))
83 node['hidden_size'] = hidden_size