在神经网络训练的过程中,会涉及到tf.nn.relu(d),也就是激活函数,这个激活函数挺起来真的很高大上,这个激活函数究竟有什么用处呢?
我们来看一个例子就知道了,这个是模仿全连接层计算的,这个激活函数就是把负数填充为0,减少神经网络的一层层计算!
import tensorflow as tf
a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3])
b = tf.constant([7, 8, 9, -10, -11, -12], shape=[3,2])
c=tf.constant([1,2,3,4],shape=[2,2])
d=tf.matmul(a,b)+c
with tf.Session() as sess:
print(sess.run(d))
print(sess.run(tf.nn.relu(d)))