tensorflow 学习笔记3 placeholder与激活函数

来源:互联网 发布:淘宝优惠券微信机器人 编辑:程序博客网 时间:2024/06/05 09:19

placeholder使用的时候和前面的variable不同的是在session运行阶段,需要给placeholder提供数据,利用feed_dict的字典结构给placeholdr变量“喂数据”。

import tensorflow as tf#placeholder 传入值  运行结果时给它一个输入值,与feed_dict绑定input1=tf.placeholder(tf.float32)input2=tf.placeholder(tf.float32)output=tf.multiply(input1,input2)with tf.Session() as sess:    print(sess.run(output,feed_dict={input1:[7.0],input2:[2.0]}))

结果:

[14.]
常见的激活函数有:

tf.nn.relutf.nn.relu6tf.nn.crelutf.nn.elutf.nn.softplustf.nn.softsigntf.nn.dropouttf.nn.bias_addtf.sigmoidtf.tanh

sigmoid:

\sigma \left( x\right) =\dfrac {1} {1+e^{-x}}


tanh函数:

\tanh \left( x\right) =2\sigma \left( 2x\right) -1


relu函数:

f\left( x\right) =\max \left( 0,x\right)


leaky relu函数:

ReLU 中当 x<0 时,函数值为 0。而 Leaky ReLU 则是给出一个很小的负数梯度值,比如 0.01。


原创粉丝点击