2 Copyright (c) 2018 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.
20 from mo.front.common.layout import get_height_dim, get_width_dim
21 from mo.graph.graph import Node
22 from mo.ops.op import Op
23 from extensions.ops.resize_factor_utils import factor_update
29 def __init__(self, graph: nx.MultiDiGraph, attrs: dict):
34 'infer': ResampleOp.resample_infer
36 super().__init__(graph, mandatory_props, attrs)
38 def supported_attrs(self):
47 def backend_attrs(self):
52 ('type', 'resample_type'),
57 def resample_infer(node: Node):
58 height_dim = get_height_dim(node.graph.graph['layout'])
59 width_dim = get_width_dim(node.graph.graph['layout'])
61 input_shape = node.in_node(0).shape
62 if input_shape is None:
64 out_shape = input_shape.copy()
65 if node.has('fw') and node.fw == 'tf':
66 dst_shape = node.in_node(1).value
67 if dst_shape is None or len(input_shape) != 4 or len(dst_shape) != 2:
69 'Node {} with op {} cannot be converted to Resample layer because there is no enough info about '
70 'src/dst shapes: src_shape = {}, dst_shape = {}'.format(node.name, node.op, input_shape, dst_shape))
71 node.type = None # prevent translation to a valid IE layer
73 out_shape[height_dim] = dst_shape[0]
74 out_shape[width_dim] = dst_shape[1]
75 node.graph.remove_edge(node.in_node(1).id, node.id)
77 if len(node.in_nodes()) == 1:
78 if node.has('width') and node.has('height'):
79 out_shape[height_dim] = node.height
80 out_shape[width_dim] = node.width
82 out_shape[height_dim] = node.factor * input_shape[height_dim]
83 out_shape[width_dim] = node.factor * input_shape[width_dim]
85 out_shape[height_dim] = node.in_node(1).shape[height_dim]
86 out_shape[width_dim] = node.in_node(1).shape[width_dim]
88 real_factor = [float(out_shape[height_dim])/input_shape[height_dim], float(out_shape[width_dim])/input_shape[width_dim]]
89 node.factor = factor_update(
92 [input_shape[height_dim], input_shape[width_dim]],
93 [out_shape[height_dim], out_shape[width_dim]],
94 node.soft_get('name'))
96 node.out_node().shape = out_shape