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.
21 from mo.front.mxnet.extractors.leaky_relu import LeakyReLUFrontExtractor
22 from mo.graph.graph import Node
23 from mo.utils.unittest.graph import build_graph
26 class TestLeakyReLUFrontExtractorOp(unittest.TestCase):
27 def test_extract_leaky_relu_layer(self):
29 {'node_1': {'type': 'Placeholder', 'kind': 'op', 'op': 'Placeholder'},
30 'act_node': {'type': 'LeakyReLU', 'kind': 'op', 'op': 'LeakyReLU', },
31 'node_2': {'type': 'Identity', 'kind': 'op'},
34 ('node_1', 'act_node'),
35 ('act_node', 'node_2'),
38 'act_node': {'symbol_dict': {'attrs': {'slope': '0.6'}}},
41 act_node = Node(graph, 'act_node')
42 act_extr_op = LeakyReLUFrontExtractor()
43 supported = act_extr_op.extract(act_node)
44 self.assertTrue(supported)
45 self.assertEqual(act_node['op'], 'ReLU')
46 self.assertEqual(act_node['negative_slope'], 0.6)
48 def test_extract_prelu_layer(self):
50 {'node_1': {'type': 'Placeholder', 'kind': 'op', 'op': 'Placeholder'},
51 'node_3': {'type': 'Placeholder', 'kind': 'op', 'op': 'Placeholder'},
52 'act_node': {'type': 'LeakyReLU', 'kind': 'op', 'op': 'LeakyReLU', },
53 'node_2': {'type': 'Identity', 'kind': 'op'},
56 ('node_1', 'act_node'),
57 ('node_3', 'act_node'),
58 ('act_node', 'node_2'),
61 'act_node': {'symbol_dict': {'attrs': {'act_type': 'prelu'}}},
62 'node_3': {'value': np.array([1], dtype=np.float32)},
64 act_node = Node(graph, 'act_node')
65 act_extr_op = LeakyReLUFrontExtractor()
66 supported = act_extr_op.extract(act_node)
67 self.assertTrue(supported)
68 self.assertEqual(act_node['op'], 'PReLU')
70 def test_extract_elu_layer(self):
72 {'node_1': {'type': 'Placeholder', 'kind': 'op', 'op': 'Placeholder'},
73 'act_node': {'type': 'LeakyReLU', 'kind': 'op', 'op': 'LeakyReLU', },
74 'node_2': {'type': 'Placeholder', 'kind': 'op'},
77 ('node_1', 'act_node'),
78 ('act_node', 'node_2'),
81 'act_node': {'symbol_dict': {'attrs': {'act_type': 'elu'}}},
84 act_node = Node(graph, 'act_node')
85 act_extr_op = LeakyReLUFrontExtractor()
86 supported = act_extr_op.extract(act_node)
87 self.assertTrue(supported)
88 self.assertEqual(act_node['op'], 'Activation')
89 self.assertEqual(act_node['operation'], 'elu')