tesnorflow minst用卷积网络做识别

本文介绍了一种使用TensorFlow实现的手写数字识别系统。该系统通过构建卷积神经网络(CNN)对MNIST数据集进行训练,并采用梯度下降优化器最小化交叉熵损失函数。文中展示了如何定义权重、偏置变量,执行卷积和池化操作,以及如何通过全连接层进行分类。
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist=input_data.read_data_sets('MNIST_data/',one_hot=True)
def weight_variable(shape):
    initial_value=tf.truncated_normal(shape=shape,stddev=0.1)
    return tf.Variable(initial_value)
def bias_variable(shape):
    initial_value=tf.constant(0.2,shape=shape)
    return tf.Variable(initial_value)
def con2d(x,w):
    return tf.nn.conv2d(x,w,strides=[1,1,1,1],padding="SAME")
def pool(x):
    return tf.nn.max_pool(x,ksize=[1,2,2,1],strides=[1,2,2,1],padding="SAME")
x=tf.placeholder(tf.float32,[None,784])
reshape_x=tf.reshape(x,[-1,28,28,1])
w1=weight_variable([5,5,1,32])
b1=bias_variable([32])
out_conv1=tf.nn.relu(con2d(reshape_x,w1)+b1)
pool_conv1=pool(out_conv1)

w2=weight_variable([5,5,32,64])
b2=bias_variable([64])
out_conv2=tf.nn.relu(con2d(pool_conv1,w2)+b2)
pool_conv2=pool(out_conv2)

out_reshape=tf.reshape(pool_conv2,[-1,7*7*64])
fc1=weight_variable([7*7*64,1024])
bfc1=bias_variable([1024])
out_fc1=tf.nn.relu(tf.matmul(out_reshape,fc1)+bfc1)

keep_prob_ratio=tf.placeholder('float')

out_dropout=tf.nn.dropout(out_fc1,keep_prob_ratio)

fc2=weight_variable([1024,10])
b_fc2=bias_variable([10])
pure_input=(tf.matmul(out_dropout,fc2)+b_fc2)
y=tf.nn.softmax(pure_input)

y_=tf.placeholder(tf.float32,[None,10])
cross_entropy=-tf.reduce_sum(y_*tf.log(y))

train_step=tf.train.GradientDescentOptimizer(0.001).minimize(cross_entropy)

accuracy=tf.reduce_mean(tf.cast(tf.equal(tf.argmax(y,1),tf.argmax(y_,1)),"float"))

initialize=tf.initialize_all_variables()
shape=tf.shape(fc2)
with tf.Session() as sess:
    sess.run(initialize)
    for i in range(20000):
        batch_x, batch_y_ = mnist.train.next_batch(10)
        sess.run(train_step,feed_dict={x:batch_x,y_:batch_y_,keep_prob_ratio:0.5})
        if(i%100==0):
            test_x,test_y=mnist.test.next_batch(100)
            result=sess.run(accuracy, feed_dict={x: test_x, y_: test_y, keep_prob_ratio: 1.0})
            print ("accuracy:%.4f"%result)
    print ("final accuracy:%.4f" %sess.run(accuracy,feed_dict={x:test_x,y_:test_y,keep_prob_ratio:1.0}))

java大数据人工智能培训学校全套教材系列课程由1000集视频构成,基本就 是1)时下流行的java培训学校主流内部教材,2)和市面上培训学校的通 行的课程体系几乎一样。所以这套课程都能自己学下来,等于上了培训学校一次,完全可以找个java工程师的工作了。 通过学习卷积神经网络概述,为什么引入神经网络识别,判断,预测,训练模型,激活函数,sigmoid激活函数,导数和切线,sigmoid激活函数如何求导,链式法则,梯度,梯度下降法与delta法则,BP(back propagation)误差逆传播神经网络卷积到底有什么作用?如何到特征提取,池化的名字由来,dropout,Anaconda Prompt的用法,Jupyter notebook的用法,Spyder的用法,建立安装Tensorflow所需的Anaconda虚拟环境,如何在Anaconda虚拟环境安装Tensorflow与Keras概念等让大家对人工智能,卷积神经网络快速入门。课程特色:专业细致,偏案例,理论强。课程软件使用:Anaconda,Spyder,Jupyter notebook重要声明:1) 如果感觉噪音大,可以选择不用耳机,加音箱或用电脑原声 2) 既然我们的名字叫人工智能深度学习卷积神经网络入门,这个课程的特点就在于成本最低的, 让你最快速的,最容易的入门。人工智能深度学习卷积神经网络入门的最大的难点在于入门入不了,从而最终放弃。俗话说师傅领进门,修行在个人。只要入了门了,后面的事都好办。选课前,务必注意本章的学习目标和内容。想学更多,注意后边的课程。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值