2 Copyright (c) 2017-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.
21 from mo.front.common.partial_infer.utils import int64_array
22 from mo.graph.graph import Node, Graph
23 from mo.ops.op import Op
26 class DepthToSpaceOp(Op):
29 def __init__(self, graph: Graph, attrs: dict):
34 'infer': DepthToSpaceOp.depth_to_space_infer
36 super().__init__(graph, mandatory_props, attrs)
39 def depth_to_space_infer(node: Node):
40 in_shape = node.in_node().shape
41 if in_shape.size != 4:
42 log.error('TensorFlow DepthToSpace operation is supported for 4D \'NHWC\' input layout only. '
43 'Current input shape is \'{}\''.format(in_shape))
46 block_size = node['block_size']
47 if C % (block_size ** 2):
48 log.error('Feature dimensions of input tensor of DepthToSpace operation have to be divisible by square of '
49 'DepthToSpace \'block_size\' parameter. Input tensor shape = {}. Feature dimension = {}. '
50 'block_size = {}'.format(in_shape, C, block_size))
52 out_shape = [N, int(H * block_size), int(W * block_size), int(C / (block_size ** 2))]
53 if np.prod(in_shape) != np.prod(out_shape):
55 node.out_node().shape = int64_array(out_shape)