tensorflow训练代码
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
mnist = input_data.read_data_sets("MNIST_data/",one_hot = True)
sess = tf.InteractiveSession() def weight_Variable(shape):
initial = tf.truncated_normal(shape,stddev = 0.1)
return tf.Variable(initial) def bias_Variable(shape):
initial = tf.constant(0.1,shape = shape)
return tf.Variable(initial) def conv2d(input,filter):
return tf.nn.conv2d(input,filter,strides = [1,1,1,1],padding = 'SAME') def max_pool_2x2(input):
return tf.nn.max_pool(input,[1,2,2,1],[1,2,2,1],padding = 'SAME') x = tf.placeholder(tf.float32,[None,784])
y = tf.placeholder(tf.float32,[None,10])
x_image = tf.reshape(x,[-1,28,28,1]) w_conv1 = weight_Variable([5,5,1,32])
b_conv1 = bias_Variable([32])
h_conv1 = tf.nn.relu(conv2d(x_image,w_conv1)+b_conv1)
h_pool1 = max_pool_2x2(h_conv1) w_conv2 = weight_Variable([5,5,32,64])
b_conv2 = bias_Variable([64])
h_conv2 = tf.nn.relu(conv2d(h_pool1,w_conv2)+b_conv2)
h_pool2 = max_pool_2x2(h_conv2) w_fc1 = weight_Variable([7*7*64,1024])
b_fc1 = bias_Variable([1024])
h_pool2_flat = tf.reshape(h_pool2,[-1,7*7*64])
h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat,w_fc1)+b_fc1) keep_prob = tf.placeholder(tf.float32)
h_fc1_drop = tf.nn.dropout(h_fc1,keep_prob) w_fc2 = weight_Variable([1024,10])
b_fc2 = bias_Variable([10])
y_conv = tf.nn.softmax(tf.matmul(h_fc1_drop,w_fc2)+b_fc2) cross_entropy = tf.reduce_mean(-tf.reduce_sum(y*tf.log(y_conv),reduction_indices = [1]))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) correct_prediction = tf.equal(tf.argmax(y_conv,1),tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32)) tf.global_variables_initializer().run()
for i in range(20000):
batch = mnist.train.next_batch(50)
if i%100 == 0:
train_accuracy = accuracy.eval(feed_dict = {x:batch[0],y:batch[1],keep_prob:1.0})
print('step %d,training accuracy %g'%(i,train_accuracy))
train_step.run(feed_dict = {x:batch[0],y:batch[1],keep_prob:0.5}) print('test accuary %g'%accuracy.eval(feed_dict={x:mnist.test.images,y:mnist.test.labels,keep_prob:1.0}))
tensorflow训练代码的更多相关文章
- TensorFlow 训练好模型参数的保存和恢复代码
		TensorFlow 训练好模型参数的保存和恢复代码,之前就在想模型不应该每次要个结果都要重新训练一遍吧,应该训练一次就可以一直使用吧. TensorFlow 提供了 Saver 类,可以进行保存和恢 ... 
- tensorflow训练线性回归模型
		tensorflow安装 tensorflow安装过程不是很顺利,在这里记录一下 环境:Ubuntu 安装 sudo pip install tensorflow 如果出现错误 Could not f ... 
- 2、TensorFlow训练MNIST
		装载自:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html TensorFlow训练MNIST 这个教程的目标读者是对机器学习和T ... 
- tensorflow训练验证码识别模型
		tensorflow训练验证码识别模型的样本可以使用captcha生成,captcha在linux中的安装也很简单: pip install captcha 生成验证码: # -*- coding: ... 
- TensorFlow训练MNIST报错ResourceExhaustedError
		title: TensorFlow训练MNIST报错ResourceExhaustedError date: 2018-04-01 12:35:44 categories: deep learning ... 
- TensorFlow.训练_资料(有视频)
		ZC:自己训练 的文章 貌似 能度娘出来很多,得 自己弄过才知道哪些个是坑 哪些个好用...(在CSDN文章的右侧 也有列出很多相关的文章链接)(貌似 度娘的关键字是"TensorFlow ... 
- 目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练
		将目标检测 的标注数据 .xml 转为 tfrecord 的格式用于 TensorFlow 训练. import xml.etree.ElementTree as ET import numpy as ... 
- 自己搞了20万张图片100个分类,tensorflow训练23万次后。。。。。。
		自己搞了20万张图片100个分类,tensorflow训练23万次后...... 我自己把训练用的一张图片,弄乱之后做了一个预测 100个汉字,20多万张图片,tensorflow CNN训练23万次 ... 
- tensorflow训练了10万次,运行完毕,对这个word2vec终于有点感觉了
		tensorflow训练了10万次,运行完毕,对这个word2vec终于有点感觉了 感觉它能找到词与词之间的关系,应该可以用来做推荐系统.自动摘要.相关搜索.联想什么的 tensorflow1.1.0 ... 
随机推荐
- Map.Entry遍历集合中的元素
			Entry是Map中的一个内部累,map.entrySet()可以得到key和value的视图给你一个比较简单的小事例public static void main(String[] args) { ... 
- 如何制作Win10系统U盘安装镜像
			准备的工具: 1.空间8G以上的U盘一个 2.系统镜像文件(ISO格式)下载:https://msdn.itellyou.cn/ 3.UltraISO 下载:https://cn.ultraiso.n ... 
- 第2天:JavaScript基础(运算符、案例、循环、冒泡以及prompt提示输入框)
			一元运算在前在后的区别 加加 var num1 = 10; //++在后面 先参与运算 再自加1 var sum1 = num1++ +10; console.log("sum1的值:&qu ... 
- Octotree Chrome安装与使用整理
			Octotree Chrome作用: 主要使你在github查看项目时可以清晰明了的看到项目的结构以及具体代码,使下载代码更具有目的性,减少不必要代码的下载,而且看起来更清楚. 效果图:(安装插件前) ... 
- 三年从前端小工到架构-知乎 Live 学习整理
			最近在知乎上学习了vczero (王利华,簋谣)的知乎Live「三年从前端小工到架构」,感觉受益匪浅,现将本次Live学习笔记记录如下. 本次 Live 主要包括以下内容 • 0-3 年的前端工程 ... 
- MemcacheHelper.cs
			using Memcached.ClientLibrary; using System; using System.Collections.Generic; using System.Linq; us ... 
- unity3d之实现各种滑动效果
			一. 点击滑动页面 新建了一个带mask的prefab,加上代码只需要将图片prefab.按钮prefab和所想添加的图片 拖进去会自动生成按钮,滑动速度可以随意调time,滑动效果用itween实现 ... 
- SASS和LESS等优缺点对比,使用方法总结 (笔记大全)
			sass优点: 用户多,更容易找到会用scss的开发,更容易找到scss的学习资源: 可编程能力比较强,支持函数,列表,对象,判断,循环等: 相比less有更多的功能: Bootstrap/Found ... 
- 浅谈移动端中的视口(viewport)
			在 PC 端,视口指的是浏览器的可视区域,其宽度和浏览器窗口的宽度保持一致.在 CSS 标准文档中,视口也被称为初始包含块,它是所有 CSS 百分比宽度推算的根源,给 CSS 布局限制了一个最大宽度. ... 
- 201610-H5项目总结
			1.首屏进入动效使用jQuery的animate(); $('.btn_driver').animate({ left:'26%' },'slow'); $('.btn_show').animate( ... 
