threshold
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
def threshold(x):
cond = tf.less(x, tf.zeros(x.shape, dtype=x.dtype))
res = tf.where(cond, tf.zeros(x.shape), tf.ones(x.shape))
return resh = np.linspace(-1,1,50)
out = threshold(h)with tf.Session() as sess:
y = sess.run(out)
plt.xlabel('Activity of Neuron')
plt.ylabel('Output of Neuron')
plt.title('Threshold Activation Function')
plt.plot(h, y)
plt.show()
![TensorFlow常用激活函数](https://img.it610.com/image/info8/7506e52b7f8746ae9ae829e42dae3603.jpg)
文章图片
Sigmoid
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
h = np.linspace(-10,10,50)
out = tf.sigmoid(h)with tf.Session() as sess:
y = sess.run(out)
plt.xlabel('Activity of Neuron')
plt.ylabel('Output of Neuron')
plt.title('Sigmoid Activation Function')
plt.plot(h, y)
plt.show()
![TensorFlow常用激活函数](https://img.it610.com/image/info8/74dce95475174e13b40dec856a251a2b.jpg)
文章图片
Tanh
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
h = np.linspace(-10,10,50)
out = tf.tanh(h)with tf.Session() as sess:
y = sess.run(out)
plt.xlabel('Activity of Neuron')
plt.ylabel('Output of Neuron')
plt.title('Tanh Activation Function')
plt.plot(h, y)
plt.show()
![TensorFlow常用激活函数](https://img.it610.com/image/info8/01946ea705bc4a63bc888cffdab386ba.jpg)
文章图片
RELU
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
h = np.linspace(-10,10,50)
out = tf.nn.relu(h)with tf.Session() as sess:
y = sess.run(out)
plt.xlabel('Activity of Neuron')
plt.ylabel('Output of Neuron')
plt.title('RELU Activation Function')
plt.plot(h, y)
plt.show()
![TensorFlow常用激活函数](https://img.it610.com/image/info8/bbb5cee6fc364ba68282b0edb852ee96.jpg)
文章图片
Softmax
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
h = np.linspace(-5,5,50)
out = tf.nn.softmax(h)with tf.Session() as sess:
y = sess.run(out)
plt.xlabel('Activity of Neuron')
plt.ylabel('Output of Neuron')
plt.title('Softmax Activation Function')
plt.plot(h, y)
plt.show()
【TensorFlow常用激活函数】
![TensorFlow常用激活函数](https://img.it610.com/image/info8/a9c17211f4074e298c6c9a62ea8db6fb.jpg)
文章图片