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.
21 from mo.front.common.partial_infer.eltwise import eltwise_infer
22 from mo.graph.graph import Node, Graph
23 from mo.ops.op import Op
30 def __init__(self, graph: Graph, attrs: dict):
31 super().__init__(graph, {
37 'infer': __class__.infer,
42 def supported_attrs(self):
44 List of attributes that can/should be set by a client.
46 return ['power', 'scale', 'shift']
49 def infer(node: Node):
50 input_nodes_cnt = len(node.in_nodes())
51 if input_nodes_cnt > 2:
52 log.error('Power layer {} must have one or two inputs (given {})'.format(node.name, len(node.in_nodes())))
55 # In case of two inputs we should check value of the second input (should be a scalar)
56 if input_nodes_cnt == 2:
57 if not node.in_node(1).has_valid('value'):
58 log.error('Power layer {} do not support dynamic power value'.format(node.name, len(node.in_nodes())))
61 if node.in_node(1).value.ndim != 0:
62 log.error('Power layer {} do not support not scalar power value'.format(node.name, len(node.in_nodes())))
65 node['power'] = np.array(node.in_node(1).value, dtype=np.float64)
66 node.graph.remove_edge(node.in_node(1).id, node.id)
68 eltwise_infer(node, lambda a: np.power(a * node.scale + node.shift, node.power))