180413 绘制tensorflow自带激活函数tf.nn.sigmoid()与tf.nn.relu()

这里写图片描述

import tensorflow as tf
import matplotlib.pyplot as plt
x = tf.placeholder(tf.float32)
y1 = tf.nn.sigmoid(x)
y2 = tf.nn.relu(x)
data = np.linspace(-5,5,100)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    y_sigmoid = sess.run(y1,feed_dict={x:data})
    y_relu = sess.run(y2,feed_dict={x:data})

fig = plt.figure(figsize=(10,5))
ax = fig.add_subplot(121)
ax.plot(data,y_sigmoid)
ax.grid()
ax.set_title('(a) Sigmoid')

ax = fig.add_subplot(122)
ax.plot(data,y_relu)
ax.grid()
ax.set_title('(b) Relu')

猜你喜欢

转载自blog.csdn.net/qq_33039859/article/details/79915048