Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / front / caffe / bias_ext_test.py
1 """
2  Copyright (c) 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 from unittest.mock import patch
18
19 from extensions.front.caffe.bias_ext import BiasToAdd
20 from mo.utils.unittest.extractors import FakeModelLayer, FakeMultiParam
21 from mo.utils.unittest.graph import FakeNode
22
23
24 class FakeBiasProtoLayer:
25     def __init__(self, val):
26         self.bias_param = val
27
28
29 class TestBias(unittest.TestCase):
30
31     @patch('extensions.front.caffe.bias_ext.embed_input')
32     def test_bias(self, embed_input_mock):
33         embed_input_mock.return_value = {}
34         params = {'axis': 1}
35         add_node = FakeNode(FakeBiasProtoLayer(FakeMultiParam(params)),
36                             FakeModelLayer([1, 2, 3, 4, 5]))
37         BiasToAdd.extract(add_node)
38
39         exp_res = {
40             'type': "Eltwise",
41             'operation': 'sum',
42             'axis': 1
43         }
44
45         for key in exp_res.keys():
46             self.assertEqual(add_node[key], exp_res[key])