Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / mo / front / caffe / extractors / crop_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
17 import unittest
18 from unittest.mock import patch
19
20 from mo.front.caffe.extractors.crop import CropFrontExtractor
21 from mo.front.common.partial_infer.crop import crop_infer
22 from mo.ops.crop import Crop
23 from mo.ops.op import Op
24 from mo.utils.unittest.extractors import FakeMultiParam
25 from mo.utils.unittest.graph import FakeNode
26
27
28 class FakeCropProtoLayer:
29     def __init__(self, val):
30         self.crop_param = val
31
32
33 class TestCropExt(unittest.TestCase):
34     @classmethod
35     def setUpClass(cls):
36         Op.registered_ops['Crop'] = Crop
37
38     def test_da_no_pb_no_ml(self):
39         self.assertRaises(AttributeError, CropFrontExtractor.extract, None)
40
41     @patch('mo.front.caffe.collect_attributes')
42     def test_crop_ext(self, collect_attributes_mock):
43         params = {
44             'axis': 0,
45             'offset': 0,
46         }
47         collect_attributes_mock.return_value = {
48             **params,
49             'test': 54,
50             'test2': 'test3'
51         }
52         fake_pl = FakeCropProtoLayer(FakeMultiParam(params))
53         fake_node = FakeNode(fake_pl, None)
54
55         CropFrontExtractor.extract(fake_node)
56
57         exp_res = {
58             'type': 'Crop',
59             'axis': 0,
60             'offset': 0,
61             'dim': None,  # set in infer
62             'infer': crop_infer
63         }
64
65         for key in exp_res.keys():
66             self.assertEqual(exp_res[key], fake_node[key])