TensorFlow常用激活函数

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常用激活函数
文章图片

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常用激活函数
文章图片

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常用激活函数
文章图片

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常用激活函数
文章图片

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常用激活函数
文章图片

    推荐阅读