Publishing 2019 R1 content
[platform/upstream/dldt.git] / model-optimizer / extensions / ops / depth_to_space_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
19 import numpy as np
20
21 from extensions.ops.depth_to_space import DepthToSpaceOp
22 from mo.graph.graph import Node
23 from mo.utils.error import Error
24 from mo.utils.unittest.graph import build_graph
25
26 nodes = {
27     'in_data_node': {'value': None, 'kind': 'data', 'shape': np.array([1, 1024, 576, 256])},
28     'DtS': {'op': 'DepthToSpace', 'kind': 'op', 'block_size': 2},
29     'out_data_node': {'value': None, 'kind': 'data', 'shape': None}
30 }
31
32 edges = [
33     ('in_data_node', 'DtS'),
34     ('DtS', 'out_data_node')
35 ]
36
37
38 class TestDepthToSpacePartialInfer(unittest.TestCase):
39     def test_tf_depth_to_space_infer(self):
40         graph = build_graph(nodes, edges)
41         dts_node = Node(graph, 'DtS')
42         DepthToSpaceOp.depth_to_space_infer(dts_node)
43         exp_shape = np.array([1, 2048, 1152, 64])
44         res_shape = graph.node['out_data_node']['shape']
45         self.assertTrue(np.array_equal(exp_shape, res_shape))
46
47     def test_tf_depth_to_space_infer_error(self):
48         graph = build_graph(nodes, edges)
49         graph.node['in_data_node']['shape'] = np.array([1024, 576, 256])
50         dts_node = Node(graph, 'DtS')
51         self.assertRaises(Error, DepthToSpaceOp.depth_to_space_infer(dts_node))
52
53     def test_tf_depth_to_space_infer_error_1(self):
54         graph = build_graph(nodes, edges)
55         graph.node['in_data_node']['shape'] = np.array([1, 1024, 576, 255])
56         dts_node = Node(graph, 'DtS')
57         self.assertRaises(Error, DepthToSpaceOp.depth_to_space_infer(dts_node))