#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的更多相关文章

  1. Android+TensorFlow+CNN+MNIST 手写数字识别实现

    Android+TensorFlow+CNN+MNIST 手写数字识别实现 SkySeraph 2018 Email:skyseraph00#163.com 更多精彩请直接访问SkySeraph个人站 ...

  2. Ubuntu16.04安装TensorFlow及Mnist训练

    版权声明:本文为博主原创文章,欢迎转载,并请注明出处.联系方式:460356155@qq.com TensorFlow是Google开发的开源的深度学习框架,也是当前使用最广泛的深度学习框架. 一.安 ...

  3. 一个简单的TensorFlow可视化MNIST数据集识别程序

    下面是TensorFlow可视化MNIST数据集识别程序,可视化内容是,TensorFlow计算图,表(loss, 直方图, 标准差(stddev)) # -*- coding: utf-8 -*- ...

  4. 基于tensorflow的MNIST手写数字识别(二)--入门篇

    http://www.jianshu.com/p/4195577585e6 基于tensorflow的MNIST手写字识别(一)--白话卷积神经网络模型 基于tensorflow的MNIST手写数字识 ...

  5. 使用Tensorflow操作MNIST数据

    MNIST是一个非常有名的手写体数字识别数据集,在很多资料中,这个数据集都会被用作深度学习的入门样例.而TensorFlow的封装让使用MNIST数据集变得更加方便.MNIST数据集是NIST数据集的 ...

  6. TensorFlow RNN MNIST字符识别演示快速了解TF RNN核心框架

    TensorFlow RNN MNIST字符识别演示快速了解TF RNN核心框架 http://blog.sina.com.cn/s/blog_4b0020f30102wv4l.html

  7. 2、TensorFlow训练MNIST

    装载自:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html TensorFlow训练MNIST 这个教程的目标读者是对机器学习和T ...

  8. 深入浅出TensorFlow(二):TensorFlow解决MNIST问题入门

    2017年2月16日,Google正式对外发布Google TensorFlow 1.0版本,并保证本次的发布版本API接口完全满足生产环境稳定性要求.这是TensorFlow的一个重要里程碑,标志着 ...

  9. Tensorflow之MNIST的最佳实践思路总结

    Tensorflow之MNIST的最佳实践思路总结   在上两篇文章中已经总结出了深层神经网络常用方法和Tensorflow的最佳实践所需要的知识点,如果对这些基础不熟悉,可以返回去看一下.在< ...

  10. TensorFlow训练MNIST报错ResourceExhaustedError

    title: TensorFlow训练MNIST报错ResourceExhaustedError date: 2018-04-01 12:35:44 categories: deep learning ...

随机推荐

  1. 多选按钮CheckBox

    main.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  2. 小程序canvas 变换

    var ctx = wx.createCanvasContext('base'); var centerX = 375/ 2; var centerY = 200; var rotate = 90; ...

  3. python Web生成token的几种方法,你确定不进来看看?

    1.使用rest_framework_jwt from rest_framework_jwt.settings import api_settings jwt_payload_handler = ap ...

  4. UITree_study

    1.Create canvas 2.Add TreeView 3.Subscribe and unsubscribe events(订阅和取消订阅事件) 4.Data bind items it's ...

  5. No 'Access-Control-Allow-Origin'跨域问题- (mysql-thinkphp) (6)

    因为ajax请求一个服务的时候,服务器端,比如thinkphp端,或者java框架,它会检测,你请求时候的域名,就是http请求的时候,request header不是会把客户端的Request UR ...

  6. SelectList类的构造函数

    SelectList类的构造函数 2016年05月23日 17:29:52 FrankyJson 阅读数 272 标签: MVC函数 更多 个人分类: MVC   SelectList 构造函数 (I ...

  7. spark sortShuffleWriter源码学习

    查看的源码为spark2.3 调用ShuffleMapTask的runTask方法 org.apache.spark.scheduler.ShuffleMapTask#runTask ShuffleM ...

  8. 每天一点点之 uni-app 框架开发 - 页面滚动到指定位置

    项目需求:在页面中,不管位于何处,点击评论按钮页面滚动到对应到位置 实现思路如下: uni.createSelectorQuery().select(".comment").bou ...

  9. 【pwnable.kr】 memcpy

    pwnable的新一题,和堆分配相关. http://pwnable.kr/bin/memcpy.c ssh memcpy@pwnable.kr -p2222 (pw:guest) 我觉得主要考察的是 ...

  10. JS - 使 canvas 背景透明

    canvas = document.getElementById('canvas1'); var context = canvas.getContext('2d');context.fillStyle ...