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.
19 from extensions.ops.resize_factor_utils import factor_update
20 from mo.front.common.layout import get_batch_dim, get_features_dim, get_height_dim, get_width_dim, shape_for_layout
21 from mo.graph.graph import Node, Graph
22 from mo.ops.op import Op
28 def __init__(self, graph: Graph, attrs: dict):
35 'infer': ResampleOp.resample_infer
37 super().__init__(graph, mandatory_props, attrs)
39 def supported_attrs(self):
48 def backend_attrs(self):
53 ('type', 'resample_type'),
58 def resample_infer(node: Node):
59 layout = node.graph.graph['layout']
60 assert len(layout) == 4
62 input_shape = node.in_node(0).shape
63 if input_shape is None:
65 in_height = input_shape[get_height_dim(layout, 4)]
66 in_width = input_shape[get_width_dim(layout, 4)]
68 if node.has('fw') and node.fw == 'tf':
69 dst_shape = node.in_node(1).value
70 if dst_shape is None or len(input_shape) != 4 or len(dst_shape) != 2:
72 'Node {} with op {} cannot be converted to Resample layer because there is no enough info about '
73 'src/dst shapes: src_shape = {}, dst_shape = {}'.format(node.name, node.op, input_shape, dst_shape))
74 node.type = None # prevent translation to a valid IE layer
76 out_height = dst_shape[0]
77 out_width = dst_shape[1]
78 node.graph.remove_edge(node.in_node(1).id, node.id)
80 if len(node.in_nodes()) == 1:
81 if node.has('width') and node.has('height'):
82 out_height = node.height
83 out_width = node.width
85 out_height = node.factor * in_height
86 out_width = node.factor * in_width
88 out_height = node.in_node(1).shape[get_height_dim(layout, 4)]
89 out_width = node.in_node(1).shape[get_width_dim(layout, 4)]
91 node.factor = factor_update(
93 [float(out_height) / in_height, float(out_width) / in_width],
94 [in_height, in_width],
95 [out_height, out_width],
96 node.soft_get('name'))
98 node.out_node().shape = shape_for_layout(layout,
99 batch=input_shape[get_batch_dim(layout, 4)],
100 features=input_shape[get_features_dim(layout, 4)],