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.
20 from mo.front.caffe.extractors.utils import get_canonical_axis_index
21 from mo.graph.graph import Node, Graph
22 from mo.ops.op import Op, PermuteAttrs
28 def __init__(self, graph: Graph, attrs: dict):
32 'infer': ArgMaxOp.argmax_infer,
36 super().__init__(graph, mandatory_props, attrs)
38 def supported_attrs(self):
46 def argmax_infer(node: Node):
47 shape = node.in_node(0).shape
51 # there are two inputs in TensorFlow. The second input is the axis for ArgMax
52 if len(node.in_nodes()) == 2:
53 if node.in_node(1).value is None:
54 log.debug('The second argument to ArgMax is None')
56 node.axis = node.in_node(1).value.item()
57 # remove the unnecessary input
58 node.graph.remove_edge(node.in_node(1).id, node.id)
60 num_top_axes = shape.size
64 out_shape = np.ones(num_top_axes, dtype=int)
66 if node.has_valid('axis'):
67 axis = get_canonical_axis_index(shape, node.axis)
69 out_shape = np.array(shape)
70 out_shape[axis] = node.top_k
71 PermuteAttrs.create_permute_attrs(node, attrs=[('axis', 'input:0')])
73 out_shape[0] = shape[0]
74 out_shape[2] = node.top_k
78 node.out_node().shape = out_shape