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 patch, mock_open
20 from mo.front.tf.loader import load_tf_graph_def
21 from mo.utils.summarize_graph import summarize_graph
23 pbtxt = 'node{name:"Placeholder"op:"Placeholder"attr{key:"dtype"value{type:DT_FLOAT}}attr{key:"shape"value{shape{dim' + \
24 '{size:1}dim{size:227}dim{size:227}dim{size:3}}}}}node{name:"Output/Identity"op:"Identity"input:"Placeholder' + \
25 '"attr{key:"T"value{type:DT_FLOAT}}}'
28 class TestingSummarizeGraph(unittest.TestCase):
29 def test_summarize_graph(self):
30 with patch('mo.front.tf.loader.open', mock_open(read_data=pbtxt)) as m:
31 graph_def, _ = load_tf_graph_def('path', False)
32 summary = summarize_graph(graph_def)
33 self.assertEqual(len(summary['outputs']), 1)
34 self.assertEqual(summary['outputs'][0], 'Output/Identity')
35 self.assertEqual(len(summary['inputs']), 1)
36 self.assertEqual('Placeholder' in summary['inputs'], True)
37 self.assertEqual(str(summary['inputs']['Placeholder']['shape']), '(1,227,227,3)')
38 self.assertEqual(str(summary['inputs']['Placeholder']['type']), 'float32')