Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / front / caffe / axpy_test.py
1 """
2  Copyright (c) 2018-2019 Intel Corporation
3
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
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 """
16 import unittest
17
18 from extensions.front.caffe.axpy import AxpyToEltwise
19 from mo.graph.graph import Node
20 from mo.utils.unittest.graph import build_graph_with_edge_attrs
21
22
23 class TestAxpyReplacer(unittest.TestCase):
24     def test_axpy(self):
25         nodes = {
26             'node_1': {'kind': 'op', 'type': 'Identity', 'op': 'Placeholder'},
27             'node_2': {'kind': 'op', 'type': 'Identity', 'op': 'Placeholder'},
28             'node_3': {'kind': 'op', 'type': 'Identity', 'op': 'Placeholder'},
29             'axpy': {'type': 'Axpy', 'kind': 'op', 'op': 'Axpy'},
30             'node_4': {'kind': 'op', 'type': 'Identity', 'op': 'Placeholder'}}
31         edges = [
32             ('node_1', 'axpy', {'in': 0}),
33             ('node_2', 'axpy', {'in': 1}),
34             ('node_3', 'axpy', {'in': 2}),
35             ('axpy', 'node_4', {'in': 0})]
36         graph = build_graph_with_edge_attrs(nodes, edges)
37         node = Node(graph, 'axpy')
38         replacer = AxpyToEltwise()
39         replacer.replace_op(graph, node)
40
41         scale_node = [node for node, attrs in list(graph.nodes(data=True)) if attrs['type'] == 'ScaleShift']
42         self.assertEqual(len(scale_node), 1)
43         add_node = [node for node, attrs in list(graph.nodes(data=True)) if attrs['type'] == 'Eltwise']
44         self.assertEqual(len(add_node), 1)