Tensorflow机器学习入门——MINIST数据集识别
参考网站:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html
import tensorflow as tf def add_layer(inputs, in_size, out_size, activation_function=None):
Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W')
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')
Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases)
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs #加载数据
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) #构建计算图
x = tf.placeholder("float", [None, 784])
y_ = tf.placeholder("float", [None,10])
y=add_layer(x,784,10,activation_function=tf.nn.softmax) #损失与训练
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) #计算准确率
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) #训练1000步
init = tf.initialize_all_variables()
with tf.Session() as sess:
sess.run(init)
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
if i%100==0:
print (sess.run(accuracy, feed_dict={x: batch_xs, y_: batch_ys}))
#验证准确率
print (sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
Tensorflow机器学习入门——MINIST数据集识别的更多相关文章
- Tensorflow机器学习入门——MINIST数据集识别(卷积神经网络)
#自动下载并加载数据 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_s ...
- Tensorflow机器学习入门——cifar10数据集的读取、展示与保存
基本信息 官网:http://www.cs.toronto.edu/~kriz/cifar.html 共60000张图片:50000张用于训练.10000张用于测试 图片大小为:32X32 数据集图片 ...
- 写给程序员的机器学习入门 (十) - 对象识别 Faster-RCNN - 识别人脸位置与是否戴口罩
每次看到大数据人脸识别抓逃犯的新闻我都会感叹技术发展的太快了,国家治安水平也越来越好了
- 写给程序员的机器学习入门 (九) - 对象识别 RCNN 与 Fast-RCNN
因为这几个月饭店生意恢复,加上研究 Faster-RCNN 用掉了很多时间,就没有更新博客了.这篇开始会介绍对象识别的模型与实现方法,首先会介绍最简单的 RCNN 与 Fast-RCNN 模型,下一篇 ...
- 写给程序员的机器学习入门 (十一) - 对象识别 YOLO - 识别人脸位置与是否戴口罩
这篇将会介绍目前最流行的对象识别模型 YOLO,YOLO 的特征是快,识别速度非常快
- Tensorflow机器学习入门——读取数据
TensorFlow 中可以通过三种方式读取数据: 一.通过feed_dict传递数据: input1 = tf.placeholder(tf.float32) input2 = tf.placeho ...
- Tensorflow机器学习入门——常量、变量、placeholder和基本运算
一.这里列出了tensorflow的一些基本函数,比较全面:https://blog.csdn.net/M_Z_G_Y/article/details/80523834 二.这里是tensortflo ...
- Tensorflow机器学习入门——ModuleNotFoundError: No module named 'tensorflow.keras'
这个bug的解决办法: # from tensorflow.keras import datasets, layers, models from tensorflow.python.keras imp ...
- Tensorflow机器学习入门——网络可视化TensorBoard
一.在代码中标记要显示的各种量 tensorboard各函数的作用和用法请参考:https://www.cnblogs.com/lyc-seu/p/8647792.html import tensor ...
随机推荐
- Dubbo源码学习总结系列三 dubbo-cluster集群模块
Dubbo集群模块的目的是将集群Invokers构造一个透明的Invoker对象,其中包含了容错机制.负载均衡.目录服务(服务地址集合).路由机制等,为RPC层提供高可用.高并发.自动发现.可治理的S ...
- CAS实现SSO单点登录
环境 cas-server-4.1.8,cas-client-3.4.0,Java-8,Maven-3,Tomcat-7.0.72 CAS Server 安装 点此进入 CAS 下载列表,选择下载 c ...
- 动态规划—distinct-subsequences
题目: Given a string S and a string T, count the number of distinct subsequences of T in S. A subseque ...
- hdu 4655 Cut Pieces(想法题)
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- Java8 时间处理类的使用实践(LocalDate...)
有了它,谁还在用Date?Calendar? 其实也不能这么绝对,毕竟还没到那个程度上.Java8 新增了处理时间的一组类(LocalDate.LocalDateTime.LocalTime),刚开始 ...
- thinkphp数据库连接
https://www.kancloud.cn/manual/thinkphp5/118059 一.配置文件定义 常用的配置方式是在应用目录或者模块目录下面的database.php中添加下面的配置参 ...
- 解决Debug JDK source 无法查看局部变量的问题方案
一.问题阐述首先我们要明白JDK source为什么在debug的时候无法观察局部变量,因为在jdk中,sun对rt.jar中的类编译时,去除了调试信息,这样在eclipse中就不能看到局部变量的值. ...
- 029:url标签使用详解
url标签使用详解: 在模版中,我们经常要写一些 url ,比如某个 a 标签中需要定义 href 属性.当然如果通过硬编码的方式直接将这个 url 写死在里面也是可以的.但是这样对于以后项目维护可能 ...
- <sql></sql>标签是干嘛的
<sql id="Base_Column_List"> id, emp_id, emp_name, org_id, org_name, corporate_name, ...
- Centos7防火墙和SELinux的开启和关闭
在虚拟机里面开启多个服务,对应多个端口,在防火墙开启的情况下,就要对外开放端口,这样客户端才能正常访问,但比较繁琐,关闭更直接点. 防火墙 临时关闭防火墙 systemctl stop firewal ...