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.
21 from extensions.front.onnx.lstm_ext import LSTMFrontExtractor
22 from mo.utils.unittest.extractors import PB
25 class LSTMExtractorTest(unittest.TestCase):
27 def _create_node(**attrs):
28 pb = onnx.helper.make_node(
30 inputs=['X', 'W', 'R', 'B',],
31 outputs=['Y', 'Y_h', 'Y_c'],
39 'type': 'RNNSequence',
44 'has_num_directions': True,
48 'gate_order': np.array([2, 0, 3, 1]),
49 'direction': 'forward',
52 def test_base_attrs(self):
53 node = self._create_node()
54 LSTMFrontExtractor.extract(node)
56 exp_res = self.base_attrs
58 for key in exp_res.keys():
59 equal = np.all(np.equal(node[key], exp_res[key], dtype=object))
60 self.assertTrue(equal)
62 def test_additional_attributes(self):
64 'activation_alpha': [1.0, 0.0, 2.0],
65 'activations': [b'relu', b'tanh', b'sigmoid'],
69 node = self._create_node(**additional_attrs)
70 LSTMFrontExtractor.extract(node)
72 exp_res = dict(**self.base_attrs, **additional_attrs)
73 exp_res['activations'] = ['relu', 'tanh', 'sigmoid']
75 for key in exp_res.keys():
76 equal = np.all(np.equal(node[key], exp_res[key], dtype=object))
77 self.assertTrue(equal, 'Values for attr {} are not equal'.format(key))