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.graph.graph import Node
22 from mo.ops.activation import Activation
23 from mo.utils.unittest.graph import build_graph
26 class TestActivationOp(unittest.TestCase):
29 'shape': np.array([227, 227, 227, 227]),
41 def test_assertion_activation_infer(self):
42 graph = build_graph(self.nodes_attributes,
44 ('node_1', 'activation_node'),
45 ('activation_node', 'node_3')
48 'activation_node': {'operation': 'test'}
50 activation_node = Node(graph, 'activation_node')
51 self.assertEqual(activation_node.op, 'Activation')
52 self.assertRaises(KeyError, Activation.infer, activation_node)
54 def test_activation_infer(self):
55 graph = build_graph(self.nodes_attributes,
57 ('node_1', 'activation_node'),
58 ('activation_node', 'node_3')
62 'value': np.array([0, 7, 3, -1])
71 graph.graph['layout'] = 'NCHW'
72 activation_node = Node(graph, 'activation_node')
73 Activation.infer(activation_node)
74 exp_shape = np.array([227, 227, 227, 227])
75 res_shape = graph.node['node_3']['shape']
76 res_value = graph.node['node_3']['value']
77 exp_value = np.array([0, 6, 3, 0])
78 for i, value in enumerate(exp_shape):
79 self.assertEqual(res_shape[i], value)
80 for i, value in enumerate(exp_value):
81 self.assertEqual(res_value[i], value)
83 def test_activation_elu_infer(self):
84 graph = build_graph(self.nodes_attributes,
86 ('node_1', 'activation_node'),
87 ('activation_node', 'node_3')
91 'value': np.array([6, -4, -2, -1])
101 graph.graph['layout'] = 'NCHW'
102 activation_node = Node(graph, 'activation_node')
103 Activation.infer(activation_node)
104 exp_shape = np.array([227, 227, 227, 227])
105 res_shape = graph.node['node_3']['shape']
106 res_value = graph.node['node_3']['value']
107 exp_value = np.array([6., -0.98168436, -0.86466472, -0.63212056])
108 for i, value in enumerate(exp_shape):
109 self.assertEqual(res_shape[i], value)
110 for i, value in enumerate(exp_value):
111 self.assertAlmostEqual(res_value[i], value)