TensorFlow之神经网络练习
来源:互联网 发布:阿里云连接管理终端 编辑:程序博客网 时间:2024/06/07 03:01
TensorFlow实现神经网络:
import tensorflow as tffrom numpy.random import RandomStatebatch_size=8
#定义权值、x、yw1=tf.Variable(tf.random_normal([2,3],stddev=1,seed=1))w2=tf.Variable(tf.random_normal([3,1],stddev=1,seed=1))biases1=tf.Variable(tf.constant(0.1,shape=[3]))biases2=tf.Variable(tf.constant(0.1,shape=[1]))x=tf.placeholder(tf.float32,shape=(None,2),name="x-input")y_=tf.placeholder(tf.float32,shape=(None,1),name="y-input")
#输入、中间层、输出计算a=tf.nn.relu(tf.matmul(x,w1)+biases1)y=tf.nn.relu(tf.matmul(a,w2)+biases2)
#定义损失函数、训练优化cross_entropy=-tf.reduce_mean(y_*tf.log(tf.clip_by_value(y,1e-10,1.0)))train_step = tf.train.AdamOptimizer(0.0001).minimize(cross_entropy)
#随机定义输入值rdm = RandomState(1)X = rdm.rand(128,2)Y = [[int(x1+x2<1)] for (x1,x2) in X]
#生成会话执行
with tf.Session() as sess: init_op = tf.global_variables_initializer() sess.run(init_op) print "w1", sess.run(w1) print "w2", sess.run(w2) print "\n" #迭代 STEPS = 10001 for i in range(STEPS): start = (i*batch_size)%128 end = start+batch_size sess.run(train_step,feed_dict={x:X[start:end],y_:Y[start:end]}) if i % 1000 == 0: total_cross_entropy = sess.run(cross_entropy,feed_dict={x:X,y_:Y}) print "After %d training step(s),cross entropy on all data is %g" % (i,total_cross_entropy)#输出损失值 print "\n" print "w1:",sess.run(w1) print "w2:",sess.run(w2)
阅读全文
0 0
- TensorFlow之神经网络练习
- tensorflow之搭建神经网络
- TensorFlow之创建神经网络
- tensorflow练习1:利用神经网络进行分类
- 机器学习算法练习之(二):Python和Tensorflow分别实现简单的神经网络
- 小白学Tensorflow之简单神经网络
- 卷积神经网络之tensorflow实现
- tensorflow之双向循环神经网络
- TensorFlow练习(二)——搭建神经网络结构
- TensorFlow练习(四)——构造神经网络
- Tensorflow之nn 简单神经网络学习
- 深度神经网络之tensorflow初体验
- tensorflow入门之实现单隐层的神经网络
- 用tensorflow训练神经网络之手写体
- Tensorflow中卷积神经网络之卷积层
- TensorFlow 之卷积神经网络一般过程
- tensorflow入门之训练简单的神经网络
- tensorflow之安装及简单神经网络搭建
- JetBrains 里不为人知的秘密(2)
- NProgress使用
- Makefile.am文件编写规则
- 利用JitPack自建Android Compile依赖库
- js获取精确宽度/高度(带小数位像素)
- TensorFlow之神经网络练习
- 周四见|公开课预告《Themis数据库审核平台》By韩锋
- Hibernate多对多数据插入时 stackoverflow Error
- android之View坐标系(view获取自身坐标的方法和点击事件中坐标的获取)
- java 环形队列简单实现
- 简单的 六数码问题 终于解决了EOF的问题
- 基于Dragonboard401c的超声波探距
- Unity中模拟鼠标事件
- C++之什么是变量