tensorflow-cnnn-mnist
#coding=utf-8
import tensorflow as tf
import numpy as np
import matplotlib .pyplot as plt
from tensorflow .examples .tutorials .mnist import input_data #define dataset mnist=input_data .read_data_sets ("/home/nvidia/Downloads/",one_hot= True ) #defien agruments batch_zize=20
iter=np.int(mnist .train.images.shape[0]/batch_zize )
print(iter ) #define learning_rate LEARNING_RATE_STEP=100
LEARNING_RATE_BASE=0.001
LEARNING_RATE_DECAY=0.99
global_step=tf.Variable (0,trainable= False )
learning_rate=tf.train.exponential_decay (learning_rate= LEARNING_RATE_BASE ,global_step= global_step ,decay_steps= LEARNING_RATE_STEP
,decay_rate= LEARNING_RATE_DECAY ,staircase= True ) #define tool def Weight_V(shape):
weight=tf.truncated_normal (shape=shape,stddev= 0.1)
return tf.Variable (weight ) def bias_V(shape):
bia_=tf.constant (shape=shape,value= 0.1)
return tf.Variable (bia_ ) def conv2d_(x,w):
return tf.nn.conv2d (x,filter= w,padding= "SAME",strides= [1,1,1,1]) def max_pool(x):
return tf.nn.max_pool (x,ksize= [1,2,2,1],strides=[1,2,2,1],padding="SAME") #define net x_input=tf.placeholder (shape=[None,784],dtype= tf.float32)
y_input=tf.placeholder (shape= [None,10],dtype= tf.float32) x =tf.reshape(x_input ,shape= [-1,28,28,1]) #
w_conv1=Weight_V(shape= [5,5,1,32])
b_conv1=bias_V(shape= [32])
c_conv1=tf.nn.relu (conv2d_(x ,w_conv1 )+b_conv1 )
m_conv1=max_pool(c_conv1 )
#14*14*32 w_conv2=Weight_V(shape= [5,5,32,64])
b_conv2=bias_V(shape= [64])
c_conv2=tf.nn.relu (conv2d_(m_conv1 ,w_conv2 )+b_conv2 )
m_conv2=max_pool(c_conv2 )
#7*7*64 w_fc1=Weight_V([7*7*64,1024])
b_fc1=bias_V(shape= [1024])
c_fc1=tf.reshape(m_conv2 ,[-1,7*7*64])
fc1=tf.nn.relu(tf.matmul(c_fc1 ,w_fc1 )+b_fc1 ) w_fc2=Weight_V(shape= [1024,10])
b_fc2=bias_V(shape= [10])
prediction=tf.nn.softmax (tf.matmul(fc1,w_fc2 )+b_fc2 ) #define # correct_accurcy=tf.equal(tf.argmax(prediction,axis=1),tf.argmax(y_input,axis=1))
# accurcy=tf.reduce_mean(tf.cast(correct_accurcy,dtype=tf.float32)) correct_accurcy=tf.equal (tf.argmax (prediction ,axis= 1),tf.argmax (y_input ,axis= 1)) accurcy=tf.reduce_mean (tf.cast(correct_accurcy ,dtype= tf.float32)) #traing backward
#
crosss_entropy =-tf.reduce_mean (y_input *tf.log(prediction ))
train_step=tf.train.GradientDescentOptimizer (learning_rate).minimize(crosss_entropy,global_step= global_step ) #initial global argumnets init=tf.global_variables_initializer () #SESS with tf.Session() as sess:
sess.run(init)
for i in range(21):
X,Y=mnist .test.next_batch(100)
for j in range(iter ):
xt,yt=mnist .train.next_batch (batch_zize )
sess.run(train_step ,feed_dict= {x_input :xt,y_input :yt}) acc=sess.run(accurcy ,feed_dict= {x_input :X,y_input :Y})
print(acc)
tensorflow-cnnn-mnist的更多相关文章
- Android+TensorFlow+CNN+MNIST 手写数字识别实现
Android+TensorFlow+CNN+MNIST 手写数字识别实现 SkySeraph 2018 Email:skyseraph00#163.com 更多精彩请直接访问SkySeraph个人站 ...
- Ubuntu16.04安装TensorFlow及Mnist训练
版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com TensorFlow是Google开发的开源的深度学习框架,也是当前使用最广泛的深度学习框架. 一.安 ...
- 一个简单的TensorFlow可视化MNIST数据集识别程序
下面是TensorFlow可视化MNIST数据集识别程序,可视化内容是,TensorFlow计算图,表(loss, 直方图, 标准差(stddev)) # -*- coding: utf-8 -*- ...
- 基于tensorflow的MNIST手写数字识别(二)--入门篇
http://www.jianshu.com/p/4195577585e6 基于tensorflow的MNIST手写字识别(一)--白话卷积神经网络模型 基于tensorflow的MNIST手写数字识 ...
- 使用Tensorflow操作MNIST数据
MNIST是一个非常有名的手写体数字识别数据集,在很多资料中,这个数据集都会被用作深度学习的入门样例.而TensorFlow的封装让使用MNIST数据集变得更加方便.MNIST数据集是NIST数据集的 ...
- TensorFlow RNN MNIST字符识别演示快速了解TF RNN核心框架
TensorFlow RNN MNIST字符识别演示快速了解TF RNN核心框架 http://blog.sina.com.cn/s/blog_4b0020f30102wv4l.html
- 2、TensorFlow训练MNIST
装载自:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html TensorFlow训练MNIST 这个教程的目标读者是对机器学习和T ...
- 深入浅出TensorFlow(二):TensorFlow解决MNIST问题入门
2017年2月16日,Google正式对外发布Google TensorFlow 1.0版本,并保证本次的发布版本API接口完全满足生产环境稳定性要求.这是TensorFlow的一个重要里程碑,标志着 ...
- Tensorflow之MNIST的最佳实践思路总结
Tensorflow之MNIST的最佳实践思路总结 在上两篇文章中已经总结出了深层神经网络常用方法和Tensorflow的最佳实践所需要的知识点,如果对这些基础不熟悉,可以返回去看一下.在< ...
- TensorFlow训练MNIST报错ResourceExhaustedError
title: TensorFlow训练MNIST报错ResourceExhaustedError date: 2018-04-01 12:35:44 categories: deep learning ...
随机推荐
- java、mysql、oracle、pgsql数据类型对应关系
看不清 请 Ctrl+鼠标滚轮 放大页面
- 修改Git的name和email
对于git的user.name 与user.email来说,有三个地方可以设置 etc/gitconfig (几乎不常用) git config --system ~/.gitconfig(对于单个用 ...
- Flask与Django哪个更好更实用呢?砖家是这么认为的
这一周我打算做一个 Flask 教程.本文先把 Flask 和 Django 做一个比对,因为我对这两个 Python Web 框架都有实际的开发经验.希望我可以帮助您选择学习哪个框架,因为学 ...
- Java并发编程之并发简介
操作系统中同时执行多个程序原因: 1.资源利用率:系统资源及硬件资源.当一个程序再等待另一个程序时,可以运行另一个程序,可提高资源利用率. 2.公平性:多个程序对计算机上的资源理论上具有同等的使用权. ...
- Python测试进阶——(2)配置PyCharm远程调试环境
新建一个Python项目 配置Deployment,用于本地文件和远程文件的同步,在pycharm的菜单栏依次找到:Tools > Deployment > Configuration 点 ...
- DBlink查看,创建于删除
1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...
- Arch系统软件列表
1. 安装统计 2. 安装列表 3. 安装说明 4. 作为依赖项的安装列表 5. 更正 mangaro使用减的方式安装系统.开箱即用的豪华版本,大部分人需要的都有了,同样包括个别用户不需要的,配置方面 ...
- 前端IT攻城狮--网址搜藏(-- 欢迎留言补充 --)
一. 插件 1.validator: https://validator.niceue.com/docs/ (一款专业表单验证插件) 2.jQuery Tabs-Eas ...
- SQL计算字符串里的子字符串出现个数
在某个页面,需要显示每条记录中有几个图片文件.图片文件名列表存储在mysql表里的photo_files字段,文件名之间用一个空格分开.类似'images\rpt201503121.jpg image ...
- Ubuntu 终端命令速查表
1.man: shell命令的说明指南 该命令代表manual,提供一个给定命令的说明指南. 用法:man <shell command> 用例:man ls 上述命令请求命令‘ls’的说 ...