Enable swish (#1682)

* Draft version of the Swish nGraph operation and fusing transformations for different approaches to express the operation

* Swish fusing transformation refactoring

* Added Swish operation and extractor for TF. Removed unfolding transformation for the operation.

* Added SwishIE. Implemented transformation to convert Swish to SwishIE.

* Code style fixes

* Updated Swish reference implementation. Added tests for shape and value inference


* Fixed code style for Python API

* Fixed unit test

* Apply review comments

* Use matcher_pass_callback

* Make m_alpha attribute protected in the SwishIE operation

* Fixed Swish op PythonAPI test
This commit is contained in:
Evgeny Lazarev authored and GitHub committed 2020-08-10 15:51:21 +03:00
1 parent 600ad8d180
commit 318d38770b
29 files changed
+1179 -101

No files matched your search

@@ -198,9 +198,9 @@ class LeakyReLU(Op):
def __init__(self, graph: Graph, attrs: dict):
super().__init__(graph, {
'type': __class__.op,
'op': __class__.op,
'infer': __class__.infer,
'type': self.op,
'op': self.op,
'infer': self.infer,
'in_ports_count': 1,
'out_ports_count': 1,
}, attrs)
@@ -265,3 +265,36 @@ class Mish(Activation):
sp_attrs = {'version': 'opset4'}
sp_attrs.update(attrs)
super().__init__(graph, sp_attrs)
class Swish(Op):
op = 'Swish'
def __init__(self, graph: Graph, attrs: dict):
mandatory_props = {
'op': self.op,
'type': self.op,
'version': 'opset4',
'infer': self.infer,
'in_ports_count': 2,
'out_ports_count': 1,
}
super().__init__(graph, mandatory_props, attrs)
@staticmethod
def infer(node: Node):
node_name = node.soft_get('name', node.id)
node.out_port(0).data.set_shape(node.in_port(0).data.get_shape())
beta = 1.0
if node.is_in_port_connected(1):
beta = node.in_port(1).data.get_value()
if beta is not None:
assert beta.ndim == 0, 'The "beta" value for node {} must be a scalar'.format(node_name)
beta = beta.item()
input_value = node.in_port(1).data.get_value()
if input_value is not None and beta is not None:
node.out_port(0).data.set_value(input_value / (1.0 + np.exp(-input_value * beta)))