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.
20 from mo.graph.graph import Node, Graph
21 from mo.ops.op import Op, PermuteAttrs
28 def __init__(self, graph: Graph, attrs: dict):
29 super().__init__(graph, {
38 def supported_attrs(self):
39 return ['axis', 'tiles']
42 def infer(node: Node):
43 shape = node.in_node().shape
45 log.error("Undefined shape for the input tiles for the Tile operation '{}'.".format(node.node))
47 shape = np.copy(shape)
49 if len(node.in_nodes()) == 2:
50 tile_array = node.in_node(1).value
51 if tile_array is None:
52 log.error('A tile values are None for a node "{}".'.format(node.name))
54 if len(shape) != len(tile_array):
55 log.error('Shape mismatch for a node "{}": {} vs {}.'.format(node.name, shape.shape, tile_array.shape))
57 non_one_tile = np.argwhere(tile_array != 1)
58 if len(non_one_tile) == 0:
60 'Redundant "Tile" operation "{}" with tile values for all dimensions equal to 1.'.format(node.name))
63 elif len(non_one_tile) == 1:
64 node['axis'] = non_one_tile[0][0]
65 node['tiles'] = tile_array[node['axis']]
68 log.warning("Tile operation with more than one dimension not equal to 1 is not supported.")
69 # do not return here to allow infer shape and values for the constant propagation case
70 node.graph.remove_edge(node.in_node(1).id, node.id)
71 elif len(node.in_nodes()) == 1: # case when tiled dimension and count are specified in node attributes
72 if not node.has_valid('axis') or not node.has_valid('tiles'):
73 log.error('Mandatory attributes "axis" or "tiles" are not specified for a Tile node "{}"'.
76 tile_array = np.ones([len(shape)], dtype=np.int64)
77 tile_array[node.axis] = node.tiles
79 log.error('Unsupported number of input parameters to Tile node "{}"'.format(node.name))
82 PermuteAttrs.create_permute_attrs(node, attrs=[('axis', 'input:0')])
83 node.out_node().shape = shape * tile_array
84 if node.in_node(0).value is not None:
85 node.out_node().value = np.tile(node.in_node(0).value, tile_array)