3.2 tensorflow 第一步
来源:互联网 发布:js在线混淆加密 编辑:程序博客网 时间:2024/06/14 23:24
from tensorflow.examples.tutorials.mnist import input_dataimport tensorflow as tfsess = tf.InteractiveSession()x = tf.placeholder(tf.float32, [None, 784])w = tf.Variable(tf.zeros([784, 10]))b = tf.Variable(tf.zeros([10]))y = tf.nn.softmax(tf.matmul(x,w) + b)y_ = tf.placeholder(tf.float32, [None, 10])cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices = [1])) train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)tf.global_variables_initializer().run()for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) train_step.run({x:batch_xs, y_: batch_ys})correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))print(accuracy.eval({x:mnist.test.images, y_: mnist.test.labels}))
tf.reduce_sum(y_ * tf.log(y), reduction_indices = [1]):
- tf.reduce_sum(input_tensor, reduction_indices=None,
keep_dims=False, name=None)
计算输入tensor元素的和,或者安照reduction_indices指定的轴进行求和
‘x’ is [[1, 1, 1] [1, 1, 1]]
tf.reduce_sum(x) ==> 6
tf.reduce_sum(x, 0) ==> [2, 2, 2]
tf.reduce_sum(x, 1) ==> [3, 3]
tf.reduce_sum(x, 1, keep_dims=True) ==> [[3], [3]]
tf.reduce_sum(x, [0, 1]) ==> 6
0 0
- 3.2 tensorflow 第一步
- TensorFlow入门第一步
- 学习TensorFlow第一步
- tensorflow30《TensorFlow实战》笔记-03 TensorFlow第一步 code
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步
- 第一步!
- 第一步
- 第一步
- L2-005. 集合相似度----set
- CCF201509-03模板生成系统
- 数据结构之快速排序
- 人脸三维重建素材
- StringBuffer和StringBuilder类
- 3.2 tensorflow 第一步
- React Native搭建开发环境
- 运算符的优先级(由高到低)
- 友情链接(MATLAB第二次作业)
- 模板类中的表达式(非类型)参数
- vue基础小结-简易留言板
- VC++连接FANUC机床实时数据采集使用FOCAS4.0版本的开发库
- uC/OS-III 学习笔记(一)——uC/OS-III移植
- Ubuntu下指定Eclipse启动的jdk