使用CNN处理MNIST数据集

这篇博客介绍了如何依据莫烦的视频教程,利用TensorFlow构建一个包含六层的卷积神经网络(CNN)来处理MNIST手写数字识别任务。网络结构包括两个卷积层和两个池化层,最后接两个全连接层,输出层用于10类分类。
摘要由CSDN通过智能技术生成

根据莫烦学习视频教程~

这里使用了six layer

  1. 卷积层1:[28,28,1] 变为[28,28,32]
  2. 池化层1:[28,28,32] 变为[14,14,32]
  3. 卷积层2:[14,14,32] 变为[14,14,64]
  4. 池化层2:[14,14,64] 变为[7,7,64]
  5. 全连接层1:7764变为1024
  6. 全连接层2:1024变为10

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import numpy as np
import os

# number 1 to 10 data

    mnist = input_data.read_data_sets('MNIST_data', one_hot=True)

def compute_accuracy(v_xs, v_ys):
    global prediction
    y_pre = sess.run(prediction, feed_dict={xs: v_xs, keep_prob: 1})
    correct_prediction = tf.equal(tf.argmax(y_pre,1), tf.argmax(v_ys,1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    result = sess.run(accuracy, feed_dict={xs: v_xs, ys: v_ys, keep_prob: 1})
    return result


def weight_variable(shape):
    initial = tf.truncat
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值