In [1]:
import tensorflow.compat.v1 as tf
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.python.framework import ops
ops.reset_default_graph()
tf.disable_eager_execution()
sess = tf.Session()
In [2]:
x_vals = np.linspace(start=-10,stop=10,num=100)
print(sess.run(tf.nn.relu([-3.,3.,10.])))
y_relu = sess.run(tf.nn.relu(x_vals))
In [3]:
plt.plot(x_vals, y_relu, 'b:', label='ReLU', linewidth=2)
plt.ylim([-5,11])
plt.legend(loc='upper left')
plt.show()
In [4]:
x_vals = np.linspace(start=-10,stop=10,num=100)
print(sess.run(tf.nn.relu6([-3.,3.,10.])))
y_relu6 = sess.run(tf.nn.relu6(x_vals))
In [6]:
plt.plot(x_vals, y_relu6, 'g-.', label='ReLU6', linewidth=2)
plt.ylim([-5,11])
plt.legend(loc='upper left')
plt.show()
In [7]:
x_vals = np.linspace(start=-10,stop=10,num=100)
print(sess.run(tf.nn.sigmoid([-1.,0.,1.])))
y_sigmoid = sess.run(tf.nn.sigmoid(x_vals))
In [8]:
plt.plot(x_vals, y_sigmoid, 'y-..', label='Sigmoid', linewidth=2)
plt.ylim([0,1])
plt.legend(loc='upper left')
plt.show()
In [9]:
x_vals = np.linspace(start=-10,stop=10,num=100)
print(sess.run(tf.nn.tanh([-1.,0.,1.])))
y_tanh = sess.run(tf.nn.tanh(x_vals))
In [10]:
plt.plot(x_vals, y_tanh, 'b:', label='Tanh', linewidth=2)
plt.ylim([-2,2])
plt.legend(loc='upper left')
plt.show()
In [11]:
x_vals = np.linspace(start=-10,stop=10,num=100)
print(sess.run(tf.nn.softsign([-1.,0.,1.])))
y_softsign = sess.run(tf.nn.softsign(x_vals))
In [13]:
plt.plot(x_vals, y_softsign, 'g-.', label='Softsign', linewidth=2)
plt.ylim([-1,1])
plt.legend(loc='upper left')
plt.show()
In [18]:
x_vals = np.linspace(start=-10,stop=15,num=100)
print(sess.run(tf.nn.softplus([-1.,0.,1.])))
y_softplus = sess.run(tf.nn.softplus(x_vals))
In [19]:
plt.plot(x_vals, y_softplus, 'r--', label='Softplus', linewidth=2)
plt.ylim([-2,15])
plt.legend(loc='upper left')
plt.show()
In [20]:
x_vals = np.linspace(start=-10,stop=10,num=100)
print(sess.run(tf.nn.elu([-1., 0., 1.])))
y_elu = sess.run(tf.nn.elu(x_vals))
In [22]:
plt.plot(x_vals, y_elu, 'k-', label='ExpLU', linewidth=0.5)
plt.ylim([-2,10])
plt.legend(loc='upper left')
plt.show()
In [12]:
plt.plot(x_vals, y_softplus, 'r--', label='Softplus', linewidth=2)
plt.plot(x_vals, y_relu, 'b:', label='ReLU', linewidth=2)
plt.plot(x_vals, y_relu6, 'g-.', label='ReLU6', linewidth=2)
plt.plot(x_vals, y_elu, 'k-', label='ExpLU', linewidth=0.5)
plt.ylim([-5,11])
plt.legend(loc='upper left')
plt.show()
In [11]:
plt.plot(x_vals, y_sigmoid, 'r--', label='Sigmoid', linewidth=2)
plt.plot(x_vals, y_tanh, 'b:', label='Tanh', linewidth=2)
plt.plot(x_vals, y_softsign, 'g-.', label='Softsign', linewidth=2)
plt.ylim([-2,2])
plt.legend(loc='upper left')
plt.show()
In [ ]: