11#! /usr/bin/python
2- # -*- coding: utf8 -*-
3-
4-
2+ # -*- coding: utf-8 -*-
53
64import tensorflow as tf
75
@@ -13,7 +11,6 @@ def identity(x, name=None):
1311 x : a tensor input
1412 input(s)
1513
16-
1714 Returns
1815 --------
1916 A `Tensor` with the same type as `x`.
@@ -37,14 +34,13 @@ def ramp(x=None, v_min=0, v_max=1, name=None):
3734 name : a string or None
3835 An optional name to attach to this activation function.
3936
40-
4137 Returns
4238 --------
4339 A `Tensor` with the same type as `x`.
4440 """
4541 return tf .clip_by_value (x , clip_value_min = v_min , clip_value_max = v_max , name = name )
4642
47- def leaky_relu (x = None , alpha = 0.1 , name = "LeakyReLU " ):
43+ def leaky_relu (x = None , alpha = 0.1 , name = "lrelu " ):
4844 """The LeakyReLU, Shortcut is ``lrelu``.
4945
5046 Modified version of ReLU, introducing a nonzero gradient for negative
@@ -67,16 +63,33 @@ def leaky_relu(x=None, alpha=0.1, name="LeakyReLU"):
6763 ------------
6864 - `Rectifier Nonlinearities Improve Neural Network Acoustic Models, Maas et al. (2013) <http://web.stanford.edu/~awni/papers/relu_hybrid_icml2013_final.pdf>`_
6965 """
70- with tf .name_scope (name ) as scope :
66+ # with tf.name_scope(name) as scope:
7167 # x = tf.nn.relu(x)
7268 # m_x = tf.nn.relu(-x)
7369 # x -= alpha * m_x
74- x = tf .maximum (x , alpha * x )
70+ x = tf .maximum (x , alpha * x , name = name )
7571 return x
7672
7773#Shortcut
7874lrelu = leaky_relu
7975
76+
77+ def swish (x , name = 'swish' ):
78+ """The Swish function, see `Swish: a Self-Gated Activation Function <https://arxiv.org/abs/1710.05941>`_.
79+
80+ Parameters
81+ ----------
82+ x : a tensor input
83+ input(s)
84+
85+ Returns
86+ --------
87+ A `Tensor` with the same type as `x`.
88+ """
89+ with tf .name_scope (name ) as scope :
90+ x = tf .nn .sigmoid (x ) * x
91+ return x
92+
8093def pixel_wise_softmax (output , name = 'pixel_wise_softmax' ):
8194 """Return the softmax outputs of images, every pixels have multiple label, the sum of a pixel is 1.
8295 Usually be used for image segmentation.
0 commit comments