TensorFlow Variable
#encoding=utf-8
import tensorflow as tf
state = tf.Variable(0,name='counter') #初始值为0,名字叫counter
#print(state.name)
one = tf.constant(1)
new_value = tf.add(state,one)
update = tf.assign(state,new_value)
# 如果定义 Variable, 就一定要 initialize
init = tf.global_variables_initializer() #初始化所有变量
with tf.Session() as sess:
sess.run(init)
for _ in range(8):
sess.run(update)
print(sess.run(state))
结果:
TensorFlow Placeholder
#encoding=utf-8
import tensorflow as tf
#在 Tensorflow 中需要定义 placeholder 的 type ,一般为 float32 形式
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
output = tf.multiply(input1,input2)
with tf.Session() as sess:
#需要传入的值放在了feed_dict={} 并一一对应每一个 input. placeholder 与 feed_dict={} 是绑定在一起出现的。
print(sess.run(output,feed_dict={input1:[7.],input2:[3.]}))
结果
TensorFlow激励函数
激励函数运行时激活神经网络中某一部分神经元,将激活信息向后传入下一层的神经系统。激励函数的实质是非线性方程。 Tensorflow 的神经网络 里面处理较为复杂的问题时都会需要运用激励函数 activation function 。
莫烦的教程写的很好,在此附上链接https://morvanzhou.github.io/tutorials/machine-learning/ML-intro/3-04-activation-function/
参考
以上的内容是学习莫烦的教程得到的学习心得和记录,他的教程讲的非常用心且透彻,附上莫烦的链接,大家可以去学习https://morvanzhou.github.io/tutorials/machine-learning/