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.
18 from unittest.mock import MagicMock
22 from mo.front.common.partial_infer.caffe_fallback import build_net
23 from mo.utils.unittest.extractors import FakeMultiParam, FakeValue
24 from mo.utils.unittest.graph import build_graph
28 def __init__(self, blobs):
30 self.reshape_blob = MagicMock(return_value=np.array([1, 1, 1, 1]))
31 self.reshape = MagicMock(return_value=np.array([1, 1, 1, 1]))
32 self.forward = MagicMock(return_value={'top_node': FakeValue(np.array([1, 3, 112, 112]))})
46 class TestCaffeNativePartialInfer(unittest.TestCase):
50 sys.modules['caffe'] = Caffe()
51 cls.nodes_attributes = {
52 'node_1': {'type': 'Input', 'kind': 'op'},
53 'node_2': {'type': 'Input', 'kind': 'op'},
54 'node_3': {'type': 'Identity', 'kind': 'op'},
55 'node_4': {'type': 'Identity', 'kind': 'op'},
56 'op_output': { 'kind': 'op', 'op': 'OpOutput'}
59 def test_build_net_equal_inputs(self):
62 'node_1': FakeValue(np.array([1, 3, 227, 227])),
63 'node_2': FakeValue(np.array([1, 3, 224, 224]))
65 my_mock_net = Net(my_blobs)
66 graph = build_graph(self.nodes_attributes,
71 ('node_4', 'op_output')
74 'node_4': {'shape': None},
75 'node_1': {'shape': np.array([1, 3, 227, 227])},
76 'node_2': {'shape': np.array([1, 3, 224, 224])},
77 'node_3': {'top': 'top_node'}
79 graph.proto_path = 'path_to_proto'
80 graph.caffemodel_path = 'path_to_proto'
82 my_mock_net.reshape.assert_not_called()
83 my_mock_net.forward.assert_called_once_with()
84 self.assertIsNotNone(graph.caffe_net)
86 def test_build_net_not_equal_inputs(self):
89 'shape': np.array([1, 3, 112, 112]),
90 'reshape': MagicMock(return_value=134)
93 'node_1': FakeMultiParam(input_node_param),
95 my_mock_net = Net(my_blobs)
96 graph = build_graph(self.nodes_attributes,
100 ('node_4', 'op_output')
102 {'node_4': {'shape': None},
103 'node_1': {'shape': np.array([1, 3, 227, 227])},
104 'node_3': {'top': 'top_node'}
106 nodes_with_edges_only=True)
107 graph.proto_path = 'path_to_proto'
108 graph.caffemodel_path = 'path_to_proto'
110 my_mock_net.reshape.assert_called_once_with()
111 my_mock_net.forward.assert_called_once_with()
112 self.assertIsNotNone(graph.caffe_net)