精华内容
下载资源
问答
  • 通过卷积神经网络识别数字0-9,识别率较高,可用来学习
  • CNN数字识别,cnn数字识别 python,matlab源码
  • CNN识别手写数字,很好的机器学习初心者学习资料,里面包含了MATLAB代码和详细的注释,可以直接运行
  • 包含了可直接运行的CNN的Lenet5模型实现手写数字识别Mnist以及介绍Lenet5模型的PPT
  • 卷积神经网络(Convolutional Neural Networks, CNN)是一类包含卷积计算且具有深度结构的前馈神经网络(Feedforward Neural Networks),是深度学习(deep learning)的代表算法之一 [1-2] 。卷积神经网络具有表征...
  • digit_recognizer:在Keras Notebook(KaggleMNIST)中实现的CNN数字识别器(0.995)
  • 主要为大家详细介绍了基于TensorFlow的CNN实现Mnist手写数字识别,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • 基于CNN的MNIST手写数字识别,最简单的卷积神经网络,附带源码和说明文档,代码有UI页面,可以实现对MNIST数字识别,也可以实现对手写录入数字识别
  • 一份基于cnn的手写数字识别的代码,供大家参考,具体内容如下# -*- coding: utf-8 -*-import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data# 加载数据集mnist = input_data.read_...

    一份基于cnn的手写数字自识别的代码,供大家参考,具体内容如下

    # -*- coding: utf-8 -*-

    import tensorflow as tf

    from tensorflow.examples.tutorials.mnist import input_data

    # 加载数据集

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

    # 以交互式方式启动session

    # 如果不使用交互式session,则在启动session前必须

    # 构建整个计算图,才能启动该计算图

    sess = tf.InteractiveSession()

    """构建计算图"""

    # 通过占位符来为输入图像和目标输出类别创建节点

    # shape参数是可选的,有了它tensorflow可以自动捕获维度不一致导致的错误

    x = tf.placeholder("float", shape=[None, 784]) # 原始输入

    y_ = tf.placeholder("float", shape=[None, 10]) # 目标值

    # 为了不在建立模型的时候反复做初始化操作,

    # 我们定义两个函数用于初始化

    def weight_variable(shape):

    # 截尾正态分布,stddev是正态分布的标准偏差

    initial = tf.truncated_normal(shape=shape, stddev=0.1)

    return tf.Variable(initial)

    def bias_variable(shape):

    initial = tf.constant(0.1, shape=shape)

    return tf.Variable(initial)

    # 卷积核池化,步长为1,0边距

    def conv2d(x, W):

    return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')

    def max_pool_2x2(x):

    return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],

    strides=[1, 2, 2, 1], padding='SAME')

    """第一层卷积"""

    # 由一个卷积和一个最大池化组成。滤波器5x5中算出32个特征,是因为使用32个滤波器进行卷积

    # 卷积的权重张量形状是[5, 5, 1, 32],1是输入通道的个数,32是输出通道个数

    W_conv1 = weight_variable([5, 5, 1, 32])

    # 每一个输出通道都有一个偏置量

    b_conv1 = bias_variable([32])

    # 位了使用卷积,必须将输入转换成4维向量,2、3维表示图片的宽、高

    # 最后一维表示图片的颜色通道(因为是灰度图像所以通道数维1,RGB图像通道数为3)

    x_image = tf.reshape(x, [-1, 28, 28, 1])

    # 第一层的卷积结果,使用Relu作为激活函数

    h_conv1 = tf.nn.relu(conv2d(x_image, W_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)

    """全连接层"""

    # 图片尺寸减小到7*7,加入一个有1024个神经元的全连接层

    W_fc1 = weight_variable([7*7*64, 1024])

    b_fc1 = bias_variable([1024])

    # 将最后的池化层输出张量reshape成一维向量

    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)

    """使用Dropout减少过拟合"""

    # 使用placeholder占位符来表示神经元的输出在dropout中保持不变的概率

    # 在训练的过程中启用dropout,在测试过程中关闭dropout

    keep_prob = tf.placeholder("float")

    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_sum(y_ * tf.log(y_conv))

    # 模型训练,使用AdamOptimizer来做梯度最速下降

    train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)

    # 正确预测,得到True或False的List

    correct_prediction = tf.equal(tf.argmax(y_, 1), tf.argmax(y_conv, 1))

    # 将布尔值转化成浮点数,取平均值作为精确度

    accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))

    # 在session中先初始化变量才能在session中调用

    sess.run(tf.global_variables_initializer())

    # 迭代优化模型

    for i in range(2000):

    # 每次取50个样本进行训练

    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}) # 模型中间不使用dropout

    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 accuracy %g" % accuracy.eval(feed_dict={

    x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))

    做了2000次迭代,在测试集上的识别精度能够到0.9772……

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。

    希望与广大网友互动??

    点此进行留言吧!

    展开全文
  • MNIST手写字 Matlab程序,包含...不依赖任何库,包含MNIST数据,BP网络可达到98.3%的识别率,CNN可达到99%的识别率。CNN比较耗时,关于CNN的程序介绍:https://blog.csdn.net/hoho1151191150/article/details/79714691
  • 针对多样化的验证码,其识别技术也很多,传统验证码技术主要分为人工识别、字典模型识别和验证码图像分割识别,其中字典模型中较为典型的Tesseract-OCR,其识别率相对较低,过程操作复杂,需要对识别错误的文字做出...
  • CNN深度学习-字符识别;可以进行单张样本的识别;源代码是进行批量的测试,无法进行单张测试;test_example_CNN_yhw.m可以直接运行
  • CNN卷积神经网络实现手写数字识别,Matlab+minist数据集都有,在matlab上可直接运行,新手友好,亲测可用。
  • 本篇文章主要介绍了PyTorch CNN实战之MNIST手写数字识别示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
  • deep-cnn-detector(和识别器)。 我使用 keras 框架和 opencv 库来构建检测器。 该检测器使用 CNN 分类器为 MSER 算法提出的区域确定数字与否。 先决条件 Python 2.7 keras 1.2.2 opencv 2.4.11 张量流-GPU == ...
  • OpenCV 印刷数字识别

    2017-11-21 13:17:16
    0-9印刷体数字识别, 参照opencv 数字识别详细教程 忘记放测试图片,要用代码者可以使用画图软件自己排版数字做测试图片
  • 一个可以识别图片中数字cnn网络,是一个竞赛的项目,需要用jupyter notebook 打开,内含训练集,测试集,以及cnn网络代码,适合人工智能初学者学习。
  • 利用matlab CNN网络进行手写体的数字识别分类
  • 一个简单的CNN程序,实现对十种手写体数字识别
  • 由于CNN模型训练效果与实际测试之间存在较大的差距,为提高自由手写数字识别率,尝试使用TensorFlow搭构CNN网络模型,在完成MNIST数据集训练的基础上实现对自由手写数字识别,并根据两种样本状态的差别和识别结果...

    摘要

    CNN卷积神经网络是图像识别和分类等领域常用的模型方法。由于CNN模型训练效果与实际测试之间存在较大的差距,为提高自由手写数字的识别率,尝试使用TensorFlow搭构CNN-LSTM网络模型,在完成MNIST数据集训练的基础上,基于python的flask框架实现对自由手写数字的识别,并展示线性回归模型、CNN模型及CNN-LSTM模型在手写数字上的识别结果。

    CNN-LSTM模型代码实现

    CNN-LSTM的tensorflow版本实现:

    def cnn_lstm(x):
        # 以正太分布初始化weight
        def weight_variable(shape):
            initial = tf.truncated_normal(shape, stddev=0.1)
            return tf.Variable(initial)
        # 以0.1这个常量来初始化bias
        def bias_variable(shape):
            initial = tf.constant(0.1, shape=shape)
            return tf.Variable(initial)
        def conv2d(x, W):
            return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
        # 池化
        def max_pool_2x2(x):
            return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],strides=[1, 2, 2, 1], padding='SAME')
        with tf.variable_scope('input'):
            x = tf.reshape(x, [-1, 28, 28, 1])
        with tf.variable_scope('conv_pool_1'):
            W_conv1 = weight_variable([5, 5, 1, 32])
            b_conv1 = bias_variable([32])
            h_conv1 = tf.nn.relu(conv2d(x, W_conv1) + b_conv1)
            h_pool1 = max_pool_2x2(h_conv1)
        with tf.variable_scope('conv_pool_2'):
            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)
        X_in = tf.reshape(h_pool2, [-1, 49, 64])
        X_in = tf.transpose(X_in, [0, 2, 1])
        with tf.variable_scope('lstm'):
            lstm_cell = tf.contrib.rnn.BasicLSTMCell(
                128, forget_bias=1.0, state_is_tuple=True)
            outputs, states = tf.nn.dynamic_rnn(
                lstm_cell, X_in, time_major=False, dtype=tf.float32)
            W_lstm = weight_variable([128, 10])
            b_lstm = bias_variable([10])
            outputs = tf.unstack(tf.transpose(outputs, [1, 0, 2]))
            y = tf.nn.softmax(tf.matmul(outputs[-1], W_lstm) + b_lstm)
        train_vars = tf.trainable_variables()
        return y, train_vars

    上面已经定义好了CNN-LSTM整个完整的模型,下面我们将在另一个.py文件下调用他。

    from model import cnn_lstm

    接着开始调用(下载)MNIST数据集,其中one_hot=True,该参数的功能主要是将图片向量转换成one_hot类型的张量输出。

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

    在调用CNN-LSTM模型后,需要在训练模型的这个.py文件定义模型,其中x = tf.placeholder为输入变量占位符,在训练前就要指定。

    with tf.variable_scope('cnn_lstm'):
        x = tf.placeholder(tf.float32, [None, 784], name='x')
        y, variables = cnn_lstm(x)

    接着为了训练模型,需要首先进行添加一个新的占位符用于输入正确值,接着定义交叉熵损失函数、学习速率等。

    y_ = tf.placeholder('float', [None, 10])
    cross_entropy = tf.reduce_mean(
        tf.nn.softmax_cross_entropy_with_logits(logits=y, labels=y_))
    train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
    correct_pred = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))

    开始训练模型之前,在Session里面启动模型,其中accuracy.eval(feed_dict={x: batch[0], y_: batch[1]})计算所学习到的模型的正确率。

    #saver = tf.train.Saver(variables)
    with tf.Session() as sess:
        merged_summary_op = tf.summary.merge_all()
        summary_write = tf.summary.FileWriter('tmp/mnist_log/1', sess.graph)
        summary_write.add_graph(sess.graph)
        sess.run(tf.global_variables_initializer())
        for i in range(20000):
            batch = data.train.next_batch(50)
            if i % 100 == 0:
                train_accuracy = accuracy.eval(feed_dict={x: batch[0], y_: batch[1]})
                print("Step %d, training accuracy %g" % (i, train_accuracy))
            sess.run(train_step, feed_dict={x: batch[0], y_: batch[1]})
        result = []
        for i in range(2000):
            batch = data.test.next_batch(50)
            result.append(sess.run(accuracy, feed_dict={x: batch[0], y_: batch[1]}))
        print(sum(result)/len(result))

    训练代码完整如下:

    data = input_data.read_data_sets('MNIST_data', one_hot=True)
    # 定义模型
    with tf.variable_scope('cnn_lstm'):
        x = tf.placeholder(tf.float32, [None, 784], name='x')
        y, variables = cnn_lstm(x)
    # 训练
    y_ = tf.placeholder('float', [None, 10])
    cross_entropy = tf.reduce_mean(
        tf.nn.softmax_cross_entropy_with_logits(logits=y, labels=y_))
    train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
    correct_pred = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
    saver = tf.train.Saver(variables)
    with tf.Session() as sess:
        merged_summary_op = tf.summary.merge_all()
        summary_write = tf.summary.FileWriter('tmp/mnist_log/1', sess.graph)
        summary_write.add_graph(sess.graph)
        sess.run(tf.global_variables_initializer())
        for i in range(20000):
            batch = data.train.next_batch(50)
            if i % 100 == 0:
                train_accuracy = accuracy.eval(feed_dict={x: batch[0], y_: batch[1]})
                print("Step %d, training accuracy %g" % (i, train_accuracy))
            sess.run(train_step, feed_dict={x: batch[0], y_: batch[1]})
        result = []
        for i in range(2000):
            batch = data.test.next_batch(50)
            result.append(sess.run(accuracy, feed_dict={x: batch[0], y_: batch[1]}))
        print(sum(result)/len(result))

    训练结束后,将CNN-LSTM模型的训练参数进行保存,其实现代码如下:

     path = saver.save(sess,os.path.join(os.path.dirname(__file__), 'data', 'cnn_lstm.ckpt'),  write_meta_graph=False,write_state=False )
    

    手写数字应用实现

    在信息化飞速发展的时代,光学字符识别是一个重要的信息录入与信息转化的手段。其中,手写体数字的识别有着非常广泛的应用(如:邮政编码,统计报表,财务报表,银行票据等等)。因此,手写数字的识别研究有着重大的现实意义,一旦研究成功并投入应用,将产生巨大的社会和经济效益。本部分在训练完十个阿拉伯数字的模型参数后,将手写数字识别的TF模型部署到Web中,前端负责获取用户在页面上手写数字图像并预处理,再向服务器发出AJAX请求,请求内容为待识别的图像。服务器端程序生成TF会话并加载训练好的模型,调用相应的视图函数将请求数据送入TF会话中计算,最后将识别结果异步回传到前端。其实现界面如下:

    左边的绘制画布是一个用canvas标签实现的320×320像素的画布。使用canvas对象的getContext()方法可得到一个绘图环境,该环境提供了在画布上绘图的方法和属性。绘制画布绑定鼠标事件的监听器,当用户按下并拖动鼠标时,可将鼠标移动的路径(经过的像素点)呈现到绘制画布上,这样用户可在绘制画布上使用鼠标书写数字。手写数字图像存储为uint8类型的像素矩阵,每一个位置的像素点包括R、G、B、A四个通道值。输入处理框为输入图像为尺寸为320×320像素原始手写数字图像应在前端完成尺寸调整和灰度化等预处理,再发送给服务器,以便减少向服务器传输的图像数据量。右边模型输出结果为三个模型预测输出的结果。

    其实现输出的结果如下:

    结论

    节省人力,物力,财力,以提高数字信息的处理效率,应用新型计算机技术进行自动识别数字成为了一个热门研究方向。本文针对基于TensorFlow深度学习框架完成手写体数字的识别方法的研究与实现,首先建立了基于TensorFlow深度学习框架的CNN-LSTM模型结构,针对手写体数据集MNIST的训练数据集进行训练之后,基于flask框架实现了一款手写数字识别Web应用程序,为TF模型在Web中部署和开发应用提供参考。

     

     

    展开全文
  • 使用cnn做手写数字识别“Artificial Intelligence is a branch of science which offers with helping machines discover solutions to complex problems in a greater human-like-fashion” (Sridhar, 2020)....

    使用cnn做手写数字识别

    “Artificial Intelligence is a branch of science which offers with helping machines discover solutions to complex problems in a greater human-like-fashion” (Sridhar, 2020). In different words, Minsky defines AI as “the science of making machines do things that would require Genius if finished by using men”.AI is a concerted effort to apprehend the complexity of human ride in the procedure of information. This addresses now not only how to scientifically represent and use complex and incomplete data however additionally how to see (Vision), pass (robotics), conversation (natural language, speech) and apprehend (memory, thought, classification).

    “人工智能是科学的一个分支,它可以帮助机器以类似人类的方式发现复杂问题的解决方案”(Sridhar,2020年)。 用不同的话来说,明斯基将人工智能定义为“使机器完成人类需要完成才能完成的事情的科学”。人工智能是共同努力,以了解人类在信息处理过程中的复杂性。 现在,这不仅解决了如何科学地表示和使用复杂且不完整的数据,而且还解决了如何查看(视觉),通过(机器人),对话(自然语言,语音)和理解(记忆,思想,分类)。

    问题域 (Problem Domain)

    Hand-written digit cognizance is the capacity of a PC system to apprehend hand-written inputs such as digits, characters, etc. from a extensive variety of sources such as emails, documents, images, letters, etc. This has been a problem of lookup for decades. Some areas of lookup consist of verification of signatures, processing of bank checks, interpretation of postal addresses from envelopes and many extra are turn out to be less difficult and extra handy through digit recognition methods. Several classification methods using Machine Learning have been developed and used for this purpose, such as K-Nearest Neighbors, SVM Classifier, Random Forest Classifier, etc., but these methods, whilst having the accuracy of 97%, are not adequate for real-world purposes.In current years, the research community has been gaining significant interest in deep learning-based strategies to remedy a range of supervised, unsupervised and reinforced getting to know problems. One of the most regularly occurring and broadly used strategies is Convolution neural networks (CNN's), a kind of neural networks which can extract relevant features robotic-ally from enter information. Here, we will learn about the implementation of well-known MNIST facts set to predict and recognize handwritten digits the use of deep gaining knowledge of techniques and Machine Learning algorithms. This is not a new topic and the MNIST information set is nonetheless very common and essential to take a look at and affirm new algorithms after quite a few decades. The project requires a lot of libraries such as primary ML libraries, deep mastering libraries, EDA (Exploratory Data Analysis) and tensor-flow the place tensor-flow is used as back-end with keras at some stage in the development process.

    H和手写数字识别功能是PC系统从大量来源(例如电子邮件,文档,图像,字母等)中识别手写输入(例如数字,字符等)的能力。这是一个问题查找数十年。 查找的某些区域包括签名验证,银行支票处理,信封中的邮政地址解释等,通过数字识别方法,发现许多其他方面的难度较小,并且非常方便。 已经开发了几种使用机器学习的分类方法并将其用于此目的,例如K最近邻,SVM分类器,随机森林分类器等,但是这些方法尽管具有97%的准确度,但不足以用于实际近年来,研究界对基于深度学习的策略以解决一系列有监督,无监督和强化的了解问题的方法越来越感兴趣。 卷积神经网络(CNN's)是最经常出现且使用最广泛的策略之一,它是一种可以从输入的信息中自动提取相关特征的神经网络。 在这里,我们将学习众所周知的MNIST事实的实现方法,这些事实集是通过使用深厚的技术知识和机器学习算法来预测和识别手写数字的。 这不是一个新话题,并且在几十年后,MNIST信息集对于查看和确认新算法非常普遍且必不可少。 该项目需要很多库,例如主要ML库,深度母版库,EDA(探索性数据分析)和张量流,在开发过程的某个阶段,将张量流用作keras的后端。

    背景 (Background)

    Generally Handwriting Character Recognition (HCR) is categorized into six phases which are acquisition of image, pre-processing of enter image, segmentation, feature extraction, classification and put up processing .

    通常,手写字符识别(HCR)分为六个阶段,即图像获取,输入图像的预处理,分割,特征提取,分类和组装处理。

    Image for post
    Block Diagram of Handwriting Character Recognition
    手写字符识别框图

    A. Image AcquisitionThe input photo is supplied to the consciousness gadget at the Image Acquisition stage. The input can be either in an photograph layout such as JPEG, BMT, etc., or a scanned image, digital camera, or any other gorgeous digital input machine or can be taken from the canvas on the person interface.

    A.图像采集在图像采集阶段,将输入的照片提供给意识小工具。 输入可以是诸如JPEG,BMT等的照片布局,也可以是扫描图像,数码相机或任何其他华丽的数字输入机,或者可以从人机界面上的画布上获取。

    B. Pre-ProcessingThe 2nd method, known as pre-processing, is the entry approach for personality cognizance and is very essential in finding out the focus quality. Preprocessing operates to normalize strokes and also to take away deviations that can minimize the accuracy rate. Preprocessing works usually on distinctive distortions such as irregular textual content size, missing points at some point of pen movement, jitters, left — proper bend and uneven spaces.

    B.预处理第二种方法,称为预处理,是个性识别的入门方法,对于找出焦点质量非常重要。 预处理的作用是使笔划归一化,并消除可能使准确率降到最低的偏差。 预处理通常针​​对明显的失真进行处理,例如不规则的文本内容大小,笔移动的某个点上的缺失点,抖动,向左弯曲(适当的弯曲)和不均匀的空间。

    C. SegmentationSegmentation is used to transform the enter representation of many characters to the individual characters. The methods used are the segmentation of words, strains and characters. Typically, it is carried out by way of isolating a single persona from a word picture. In addition, the contents are processed in a way that is like a tree. In the initial scenario, the line histogram is used to phase the lines. After that, each level, the characters are retrieved by a approach known as histogram, and subsequently they are retrieved.

    C. SegmentationSegmentation用于将许多字符的输入表示形式转换为单个字符。 所使用的方法是单词,单词和字符的分割。 通常,它是通过从单词图片中分离单个角色来实现的。 另外,以类似于树的方式处理内容。 在初始方案中,线直方图用于对线进行定相。 然后,在每个级别上,通过称为直方图的方法来检索字符,然后对其进行检索。

    D. Feature ExtractionThe aim of the extraction characteristic is to permit the extraction of the sample that is most important for classification. Some of the Extraction Function techniques such as Principle Component Analysis (PCA), Scale Invariant Feature Extraction (SIFT), Linear Discriminant Analysis (LDA), Histogram, Chain Code (CC), Zoning and Gradient-based applied sciences can also be used to get rid of the traits of character characters. All of these functions are used to educate the system. Each of the segmented pictures is taken with a pixel of dimension 28* 28 .By flattening the array into a vector of 28 * 28 = 784 numbers, the photograph now converges to a minimal bunch of arrays in a quite high-quality structure 784-cell dimension. The photograph now turns into a n dimensional array tensor.

    D.特征提取提取特征的目的是允许提取对于分类最重要的样品。 某些提取函数技术(例如主成分分析(PCA),尺度不变特征提取(SIFT),线性判别分析(LDA),直方图,链码(CC),基于分区和渐变的应用科学)也可以用于摆脱人物角色的特征。 所有这些功能都用于教育系统。 每张分割后的图片都是使用尺寸为28 * 28的像素拍摄的。通过将阵列展平为28 * 28 = 784个数字的矢量,该照片现在会聚为具有相当高质量结构的最小阵列阵列784-单元尺寸。 现在,照片变成了维数张量。

    E. ClassificationDecision-making takes vicinity at some point of the classification process. The extracted attributes are used to become aware of the characters. Different classifiers algorithms are used, such as SVM and Neural Networks. The classifiers sort the precise input function with reserved sample and find the best matching input classification for which Soft Max Regression is being used. Soft Max regression assigns each result with the probability so classification will become easy. This essentially incorporates all the proof this obtains through using components and then transforms it into the conceivable chances .

    E.分类决策在分类过程中的某个时刻临近。 提取的属性用于识别字符。 使用了不同的分类器算法,例如SVM和神经网络。 分类器使用保留的样本对精确的输入函数进行排序,并找到使用Soft Max回归的最佳匹配输入分类。 Soft Max回归通过概率分配每个结果,因此分类变得容易。 这本质上包含了通过使用组件获得的所有证据,然后将其转化为可以想到的机会。

    F. Post-ProcessingThe Post-processing is the last and ultimate phase of persona recognition. It is the procedure whereby herbal language is used to right the misclassified output. It procedures output by means of getting it after a recognition of the shape. If the shape is diagnosed basically then the accuracy can be increased in accordance to language knowledge. For exclusive handwriting inputs, shape recognizers behave differently.Since 1998, researchers have been learning the hassle of handwritten digit focus with almost all the algorithms developed with the aid of then and even up till now. The rate of test blunders reduced from 12% in 1988 per linear classifier to 0.23% in 2012 through Convolutionary networks, and extra and extra facts scientists and computer studying experts are attempting to increase and validate unsupervised getting to know methods such as auto encoders and deep getting to know models.The MNIST database consists of 70000 handwritten digitized numerals dispensed in ten different classes. For training purposes, the entire dataset is divided into 60,000 images, and the ultimate ten thousand is reserved for the check collection. In this work in the interval[0,1], the gray level values of every pixel are coded the use of a price of 0 for white pixels and 1 for black pixel.In the MNIST dataset, the records is already properly prepared: the pics have been founded in a 28x28 picture by computing the core of the pixel mass and translating the picture to role this point at the core of the 28x28 field. The coaching set consists of 30,000 patterns from SD-3 and 30,000 patterns from SD-1 and the take a look at set consisted of 5,000 SD-3 patterns, and 5,000 SD-1 patterns

    F.后处理后处理是角色识别的最后也是最终阶段。 这是使用草药语言纠正错误分类的输出的过程。 它通过在识别形状后获取输出来对输出进行处理。 如果基本上诊断出形状,则可以根据语言知识来提高精度。 自1998年以来,研究人员一直在学习手写数字聚焦的麻烦,几乎所有的算法都是借助当时甚至直到现在才开发出来的。 通过卷积网络,测试失误的比率从1988年的每个线性分类器的12%降低到2012年的0.23%,科学家和计算机研究专家的越来越多的事实正试图增加和验证无监督的自动编码器和深度编码器等方法。 MNIST数据库由70000个手写数字化数字组成,分为十个不同类别。 为了进行培训,将整个数据集划分为60,000张图像,最后一万张保留用于支票收集。 在区间[0,1]中的工作中,每个像素的灰度值使用白色像素的价格0和黑色像素的价格1进行编码。在MNIST数据集中,记录已正确准备:通过计算像素质量的核心并将图片转换为28x28场核心的这一点,可以在28x28图片中创建图片。 教练组由SD-3的30,000个模式和SD-1的30,000个模式组成,看一下由5,000个SD-3的模式和5,000个SD-1的模式组成的集合

    Image for post
    Sample Dataset
    样本数据集

    方法论(使用CNN分类器) (Methodology(Using CNN Classifier))

    Handwritten digit identification has come to be a subject of hobby among researchers. A giant variety of papers and articles about this situation are being posted in these days. It is proven in lookup that Deep Learning algorithms such as multilayer CNN the use of Keras with Tensorflow grant the absolute best accuracy compared to the most normally used machine getting to know algorithms such as SVM, KNN & RFC (Siddique et al., 2019). Because of its very best accuracy, Convolutional Neural Network (CNN) is being used for this project.One of the earliest rankings was posted with the aid of (Lecun et al., 1998) themselves, which includes references up to 2012 (Baldominos et al., 2019). “It can be effortlessly validated that the early computer getting to know techniques used by way of (Lecun et al., 1998) protected linear classifiers (whose error rate stages from 7.6 to 12%), K-nearest neighbors procedures (K-NN, ranging from 1.1 to 5%), non-linear classifiers (about 3.5%), help vector machines (SVM, from 0.8 to 1.4%), neural networks (NN, from 1.6 to 4.7%) and convolutional neural networks (CNN, from 0.7 to 1.7%)”. It is notable that the additional facts results, are higher carried out through a Convolutionary neural network besides distortion or preprocessing in (Lecun et al., 1998) used to be 0.95% (Baldominos et al., 2019).CNNs are beneficial mannequin category for both supervised and unsupervised gaining knowledge of paradigms, the place K-NN is used for unsupervised learning, and SVM is used for supervised learning. The supervised getting to know mechanism is the one the place the system enter and outputs (true labels) are identified and a mapping between the two is discovered. In the unsupervised gaining knowledge of mechanism, the proper labels for a given set of inputs are no longer known, and the mannequin ambitions to estimate the underlying distribution of data sample inputs (Khan et al., 2018).The points of Convolutionary neural networks, together with the capability to extract information from multidimensional sources, provide them with a very useful option for solving laptop vision problems. Since the assignment is about extracting the elements from an photo and is associated to computer imaginative and prescient problems; hence, convolutional neural community is used (Baldominos et al., 2019)To recognize the handwritten digits, a seven-layered convolutional neural community with one input layer accompanied by hidden layers and two output layer is designed and illustrated below.

    手写数字识别已成为研究人员的爱好之一。 如今,有关此情况的大量论文和文章都在发布。 在查找中证明,与最常使用的机器了解诸如SVM,KNN和RFC之类的算法相比,诸如多层CNN之类的深度学习算法与Tensorflow一起使用Keras可以提供绝对最佳的准确性(Siddique等人,2019) 。 由于卷积神经网络(CNN)的准确性最高,因此被用于该项目。(Lecun等人,1998)自己发布了最早的排名之一,其中包括直到2012年的参考文献(Baldominos等)等(2019)。 “可以毫不费力地验证,早期计算机了解(Lecun等人,1998)使用的技术保护了线性分类器(错误率从7.6%降至12%),K近邻法(K-NN)。 ,范围从1.1到5%),非线性分类器(约3.5%),帮助向量机(SVM,从0.8到1.4%),神经网络(NN,从1.6到4.7%)和卷积神经网络(CNN,从0.7到1.7%)”。 值得注意的是,除了(Lecun等人,1998)中的失真或预处理(0.9%)(Baldominos等人,2019)之外,通过卷积神经网络进行的其他事实结果要更高(CalNNs是有益的人体模型)。对于有监督和无监督的范例知识获取,将K-NN用于无监督学习,将SVM用于有监督学习。 有监督的了解机制是一种识别系统输入和输出(真实标签)并在两者之间建立映射的地方。 在无监督的机制知识中,对于给定输入集的合适标签不再是已知的,并且人体模型雄心勃勃地估计数据样本输入的基础分布(Khan等人,2018)。以及从多维来源提取信息的功能,为他们提供了解决笔记本电脑视觉问题的非常有用的选项。 由于作业是从照片中提取元素,并且与计算机的想象力和先验问题相关联; 因此,使用卷积神经社区(Baldominos等人,2019)来识别手写数字,下面设计并说明了一个七层的卷积神经社区,其中一个输入层伴有隐藏层,两个输出层。

    Image for post
    CNN Architecture
    CNN架构

    算法 (Algorithm)

    CNN object classification mannequin takes, analyzed and classifies an enter photo which in our case is digits under a positive category. Deep learning allows CNN fashions to be skilled and tested. photograph is transmitted via a collection of filters (kernels), pooling and Fully connected convolution layers and makes use of Softmax to classify an object with probabilistic values between zero and 1.

    CNN对象分类模型对输入的照片进行拍摄,分析和分类,在我们的示例中,该照片是正数类别下的数字。 深度学习可让CNN时尚技术得到测试。 照片通过过滤器(内核),池和全连接卷积层的集合进行传输,并利用Softmax对概率值为0到1的对象进行分类。

    A CNN consists of a lot of layers. These layers when used repeatedly, lead to a formation of a Deep Neural Network. The fundamental types of layers used to build a CNN are:1. InputThis layer holds the uncooked pixel values of photograph and convert it to grayscale pics using 28x28 matrix of pixels.2. Convolutional LayerThis layer gets the effects of the neuron layer that is linked to the enter regions. The wide variety of filters to be used in this layer is described here. Each filter may additionally be a 5x5 window that slider over the input records and receives the pixel with the most intensity as the output.3. Rectified Linear Unit (ReLU) LayerThis layer applies an thing smart activation function on the picture records and makes use of again propagation techniques. ReLU function is utilized in order to preserve the equal values of the pixels and not being changed by means of the returned propagation.4. Pooling LayerDown-sampling operation along the spatial dimensions (width, height), resulting in volume is utilized in this layer.5. Fully Connected LayerThis layer is used to compute the score instructions that potential which class has the maximum score corresponding to the enter digits. The category label with the largest likelihood is chosen as the ultimate classification from the network and proven in the output.

    CNN 的由很多层的。 重复使用这些层会导致形成深度神经网络。 用于构建CNN的基本层类型为:1。 输入该层保存未煮过的照片像素值,并使用28x28像素矩阵将其转换为灰度图片2。 卷积层该层获得链接到输入区域的神经元层的效果。 此处介绍了此层要使用的各种过滤器。 每个滤镜还可以是一个5x5的窗口,它可以在输入记录上滑动并接收强度最高的像素作为输出。3。 整流线性单元(ReLU)层该层在图片记录上应用了智能智能激活功能,并再次使用了传播技术。 利用ReLU函数来保留像素的相等值,并且不通过返回的传播对其进行更改。4。 沿空间维度(宽度,高度)合并LayerDown采样操作,从而在该层中利用体积5。 完全连接层该层用于计算得分指令,以指示哪个类别具有与输入数字相对应的最大得分。 从网络中选择可能性最大的类别标签作为最终分类,并在输出中进行验证。

    实作 (Implementation)

    A. TensorflowTensorflow is used as backend in the application of this project. TensorFlow is an brilliant records circulation in the Machine Learning Library made by means of the Google Brain Team and made open supply in 2015. It is designed to ease the use and greatly relevant to each numeric and neural gadget troubles simply like different spaces. TensorFlow is essentially a low-level math-entangled tool that pursuits experts who apprehend what they’re doing to construct exploratory studying structures, play around with them, and turn them into running programs. For the most part, it can be considered as a programming context in which equations can be entitled as graphs. Math things to do are spoken by using nodes in the graph, and the edges include the multidimensional facts clusters (tensors) linked to them.

    答:TensorflowTensorflow在此项目的应用程序中用作后端。 TensorFlow是由Google Brain团队在机器学习库中进行的出色记录发行,并于2015年公开供应。它的设计易于使用,并且与每个数字和神经小工具问题(如不同的空间)都非常相关。 TensorFlow本质上是一个低级的,纠缠于数学的工具,它吸引着那些了解他们在做什么的专家,这些专家正在构造探索性的学习结构,对其进行处理,然后将它们变成正在运行的程序。 在大多数情况下,可以将其视为等式可以称为图形的编程环境。 通过使用图中的节点可以说出要进行的数学运算,并且边缘包括与它们链接的多维事实簇(张量)。

    B. PythonPython is used for the duration of the implementation of assignment the place several traces of code had been brought in order to accomplish the assignment requirements. Python is typically used globally, and is a high-level programming language. It was once implemented in particular for application dominance, and its language shape allows software program engineers to carry thoughts in fewer traces of code. Python is a programming language which gives the chance to work shortly and more correctly organize frameworks.

    B. PythonPython用于执行分配的过程中,为了实现分配要求,已放置了几条代码痕迹。 Python通常在全球范围内使用,是一种高级编程语言。 它曾经是为实现应用程序优势而特别实现的,并且其语言形状使软件程序工程师可以用更少的代码来表达思想。 Python是一种编程语言,它使人们有机会在短期内更正确地组织框架。

    C. AnacondaAnaconda is used as IDE all through the implementation of the project. Anaconda is a free and open-source appropriation of the Python and R programming for logical figuring such as statistics science, AI applications, instruction of large-scale information, prescient investigation, etc. Anaconda accompanies over 1,400 programs just like the Conda package and digital surroundings director, Anaconda Navigator, so it takes the want to determine out how each library can be freely added.

    C. AnacondaAnaconda在整个项目实施过程中均用作IDE。 Anaconda是Python和R编程的一种免费开放源代码,用于逻辑计算,例如统计科学,AI应用程序,大规模信息的指令,有先见之明等。Anaconda随附1400多个程序,例如Conda软件包和数字环境总监Anaconda Navigator,因此需要确定如何自由添加每个库。

    D. KerasKeras is used to build model to arrange the layers in the course of the implementation of this project. Keras is a high-level neural community API written in Python that can run on top of TensorFlow, CNTK, or Theano. It used to be developed with a focal point on allowing for quickly experimentation. The key to doing true lookup is being capable to go from notion to result with the least delay viable.Keras approves for handy and speedy prototyping (through person friendliness, modularity, and extensibility). Similarly, it supports each convolutional networks and recurrent networks, as properly as combinations of the two and runs seamlessly on CPU and GPU.

    D. KerasKeras用于构建模型,以在该项目的实施过程中安排各层。 Keras是用Python编写的高级神经社区API,可以在TensorFlow,CNTK或Theano之上运行。 它过去的开发重点是允许快速进行实验。 进行真正查找的关键是能够从概念到结果的延迟最小化。Keras批准了方便快捷的原型制作方法(通过人性化,模块化和可扩展性)。 同样,它支持每个卷积网络和循环网络,以及两者的组合,并且可以在CPU和GPU上无缝运行。

    E. NumPyNumPy is used for mathematical calculations to print out the predict records in this project. NumPy is the core bundle with Python for scientific computing. It is a versatile sophisticated (broadcasting) with N-dimensional array object characteristic software program for combining C / C++ and Fortran code, advantageous linear algebra, Fourier transform, and random number capabilities.

    E. NumPyNumPy用于数学计算,以打印出该项目中的预测记录。 NumPy是Python用于科学计算的核心软件包。 它是具有N维数组对象特征软件程序的通用复杂(广播)程序,用于组合C / C ++和Fortran代码,有利的线性代数,傅立叶变换和随机数功能。

    F. MatplotlibMatplotlib is used to plot model accuracy and loss in a graphical view in this project. Matplotlib is a Python 2D plotting library that produces pleasant figures for the publication throughout platforms in a variety of hardcopy formats and interactive environments. Matplotlib can be used in Python scripts, Python and IPython shells, Jupyter notebook, Web software servers, and four interface toolkits for graphical users.

    F. MatplotlibMatplotlib用于在此项目的图形视图中绘制模型的准确性和损失。 Matplotlib是一个Python 2D绘图库,可以在各种硬拷贝格式和交互式环境中为整个平台的发布提供令人愉悦的图形。 Matplotlib可用于Python脚本,Python和IPython Shell,Jupyter笔记本,Web软件服务器以及四个图形用户界面工具包。

    取得的成果 (Achieved Results)

    At first, required libraries and packages are imported during the implementation of project.

    起初 ,所需的库和包工程的实施过程中导入。

    Image for post

    Then, object of the MNIST dataset is created and later loaded through the help of Tensorflow backend using Keras. After that, total number of train along with their dimension and test data set is printed out in order to view total number of elements present in the dataset.

    然后,创建MNIST数据集的对象,然后使用Keras在Tensorflow后端的帮助下加载该对象。 之后,打印出火车的总数及其尺寸和测试数据集,以查看数据集中存在的元素总数。

    Image for post

    After the dataset is loaded, one of the images from the training dataset is loaded and displayed in gray scale format by using matplotlib library.

    加载数据集后,将使用matplotlib库加载训练数据集中的图像之一并以灰度格式显示。

    Image for post

    Then the training and testing data sets are normalized where image data values are converted in terms of 0 and 1.

    然后对训练和测试数据集进行归一化,其中将图像数据值转换为0和1。

    Image for post

    After normalizing the data, a CNN model is created using keras library. Then the Flatten layer is added into the model. Then after, input and hidden layer followed by output layers are built using CNN algorithm.

    标准化数据后,使用keras库创建CNN模型。 然后,将Flatten图层添加到模型中。 然后,使用CNN算法先构建输入层和隐藏层,再构建输出层。

    Image for post

    After building the model successfully, model is compiled using Adam optimization algorithm where this algorithm is used for training Deep Neural Networks (DNN).

    成功构建模型后,使用Adam优化算法编译模型,其中该算法用于训练深度神经网络(DNN)。

    Image for post

    After compiling the model, model is fit to train data train and training is started using train data set, due to which cross entropy loss and accuracy of the model can be achieved while training the data from dataset.

    编译模型后,将模型拟合为训练数据训练,并使用训练数据集开始训练,由于在训练来自数据集的数据时可以实现交叉熵损失和模型的准确性。

    Image for post

    After the completion of training of the data set, performance of the model is evaluated using test data set, as well as accuracy and loss of data set is achieved.

    在完成数据集的训练之后,使用测试数据集评估模型的性能,并获得数据集的准确性和损失。

    Image for post

    After evaluation of model, prediction of the model is made using test data set.

    在评估模型之后,使用测试数据集对模型进行预测。

    Image for post

    Then, predicted data is printed and displayed using the index of the array.

    然后,使用数组的索引打印和显示预测数据。

    Image for post

    After the test data of the model is predicted, all available test data set (Image) in the trained model is reshaped to width and height of 28 respectively.

    预测模型的测试数据后,将训练后的模型中的所有可用测试数据集(图像)分别调整为28的宽度和高度。

    Image for post

    After the image is re shaped, one of the images followed with its label from the test data set is displayed using matplotlib library.

    调整图像形状后,将使用matplotlib库显示其中一张图像以及来自测试数据集的标签。

    Image for post

    Then, graph is plotted to measure accuracy of the built model using train and test dataset.

    然后,绘制图形以使用训练和测试数据集测量构建模型的准确性。

    Image for post

    Then, graph is also plotted to measure loss of the built model using train and test dataset.

    然后,还绘制图形以使用训练和测试数据集测量构建模型的损失。

    Image for post

    After that, image is plotted in gray scale view followed with their predicted label, true label and accuracy. Color is also defined in the class to segregate the expected result outcome.

    之后,在灰度视图中绘制图像,并附上其预测标签,真实标签和准确性。 在类中还定义了颜色,以隔离预期结果。

    Image for post

    Since, the data set is too huge, it will be difficult to display the whole data set images. So that, number of rows and columns is assigned to display the limited images from the data sets.

    由于数据集太大,因此将难以显示整个数据集图像。 因此,分配了行数和列数以显示数据集中的受限图像。

    Image for post
    Final Result
    最后结果

    结论 (Conclusion)

    The project of the undertaking is just to create a model which can recognize the digits using MNIST datasets however it can be prolonged to letters and then a person’s handwriting. It can be used by countless organization, schools, banks and even for family activities.Handwritten digit focus will be beneficial for government bodies or any different organization to identify citizenship identification range which helps in automation. Likewise, license card quantity of any individual can be diagnosed thru this system. Similarly, it can be used for academic reason the place student can learn and recognize the real world solution making use of this system. Similarly, postal addresses, bank cheque digit consciousness can be made less complicated thru automation the usage of this system.

    这项工作的目的只是创建一个可以使用MNIST数据集识别数字的模型,但是可以将其扩展为字母,然后再扩展为人的笔迹。 它可以被无数的组织,学校,银行甚至家庭活动使用。手写数字焦点将有利于政府机构或任何其他组织识别有助于自动化的公民身份识别范围。 同样,可以通过该系统诊断任何个人的许可证卡数量。 同样,出于学术原因,它也可以用于学生可以使用该系统学习和认识现实世界的解决方案。 同样,通过自动使用该系统,可以使邮政地址,银行支票数字意识变得不那么复杂。

    翻译自: https://medium.com/analytics-vidhya/hand-written-digit-recognition-using-cnn-classification-process-explanation-f6d75dcb72bb

    使用cnn做手写数字识别

    展开全文
  • Python开发,基于TensorFlow+MNIST,含数据集与训练好的模型,已经打包为exe,带UI界面
  • keras实战-入门之手写数字识别CNN

    千次阅读 2019-06-27 21:30:36
    keras实战-入门之手写数字识别CNN手写数字识别 手写数字识别 cnn的大致原理可以看我的文章,应该比较直观了,可以看到效果比全连接的好,因为他除了提取了像素信息,还提取了像素之间的空间位置信息。 import numpy ...

    keras实战-入门之手写数字识别CNN

    手写数字识别

    cnn的大致原理可以看我的文章,应该比较直观了,可以看到效果比全连接的好,因为他除了提取了像素信息,还提取了像素之间的空间位置信息。

    import numpy as np
    from keras.utils import np_utils
    from keras.datasets import mnist
    
    np.random.seed(11)
    
    (x_train_image,y_train_label),(x_test_image,y_test_label)=mnist.load_data()
    
    print('train data=',len(x_train_image))
    print('test data=',len(x_test_image))
    
    train data= 60000
    test data= 10000
    
    print('y_train_label',x_train_image.shape)
    print('y_train_label',y_train_label.shape)
    
    y_train_label (60000, 28, 28)
    y_train_label (60000,)
    
    print('x_test_image:',x_test_image.shape)
    print('y_test_label:',y_test_label.shape)
    
    x_test_image: (10000, 28, 28)
    y_test_label: (10000,)
    
    #这里跟DNN不一样,因为图像,有宽 高 通道 
    x_train4D=x_train_image.reshape(x_train_image.shape[0],28,28,1).astype('float32')
    x_test4D=x_test_image.reshape(x_test_image.shape[0],28,28,1).astype('float32')
    print(x_train4D.shape)
    print(x_test4D.shape)
    
    (60000, 28, 28, 1)
    (10000, 28, 28, 1)
    
    x_train_normalize=x_train4D/255
    x_test_normalize=x_test4D/255
    
    y_train_oneHot=np_utils.to_categorical(y_train_label)
    y_test_oneHot=np_utils.to_categorical(y_test_label)
    
    from keras import Sequential
    from keras.layers import Dense,Dropout,Flatten,Conv2D,MaxPool2D
    
    model=Sequential()
    
    #卷积层 
    model.add(Conv2D(filters=16,kernel_size=(5,5),padding='same',input_shape=(28,28,1),activation='relu'))
    
    #池化层
    model.add(MaxPool2D(pool_size=(2,2)))
    
    model.add(Conv2D(filters=36,kernel_size=(5,5),padding='same',activation='relu'))
    
    model.add(MaxPool2D(pool_size=(2,2)))
    
    #随机忽略掉部分节点
    model.add(Dropout(0.25))
    
    model.add(Flatten())
    
    model.add(Dense(units=128,activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(10,activation='softmax'))
    
    print(model.summary())
    
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    conv2d_5 (Conv2D)            (None, 28, 28, 16)        416       
    _________________________________________________________________
    max_pooling2d_6 (MaxPooling2 (None, 14, 14, 16)        0         
    _________________________________________________________________
    conv2d_6 (Conv2D)            (None, 14, 14, 36)        14436     
    _________________________________________________________________
    max_pooling2d_7 (MaxPooling2 (None, 7, 7, 36)          0         
    _________________________________________________________________
    dropout_7 (Dropout)          (None, 7, 7, 36)          0         
    _________________________________________________________________
    flatten_3 (Flatten)          (None, 1764)              0         
    _________________________________________________________________
    dense_5 (Dense)              (None, 128)               225920    
    _________________________________________________________________
    dropout_8 (Dropout)          (None, 128)               0         
    _________________________________________________________________
    dense_6 (Dense)              (None, 10)                1290      
    =================================================================
    Total params: 242,062
    Trainable params: 242,062
    Non-trainable params: 0
    _________________________________________________________________
    None
    
    model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
    
    train_history=model.fit(x_train4D,y_train_oneHot,validation_split=0.2,epochs=10,batch_size=300,verbose=2)
    
    Train on 48000 samples, validate on 12000 samples
    Epoch 1/10
     - 3s - loss: 0.0543 - acc: 0.9835 - val_loss: 0.0393 - val_acc: 0.9893
    Epoch 2/10
     - 3s - loss: 0.0515 - acc: 0.9842 - val_loss: 0.0413 - val_acc: 0.9888
    Epoch 3/10
     - 3s - loss: 0.0450 - acc: 0.9859 - val_loss: 0.0433 - val_acc: 0.9886
    Epoch 4/10
     - 3s - loss: 0.0458 - acc: 0.9855 - val_loss: 0.0466 - val_acc: 0.9882
    Epoch 5/10
     - 3s - loss: 0.0419 - acc: 0.9869 - val_loss: 0.0453 - val_acc: 0.9882
    Epoch 6/10
     - 3s - loss: 0.0430 - acc: 0.9866 - val_loss: 0.0480 - val_acc: 0.9878
    Epoch 7/10
     - 3s - loss: 0.0435 - acc: 0.9860 - val_loss: 0.0475 - val_acc: 0.9874
    Epoch 8/10
     - 3s - loss: 0.0365 - acc: 0.9875 - val_loss: 0.0480 - val_acc: 0.9888
    Epoch 9/10
     - 3s - loss: 0.0387 - acc: 0.9884 - val_loss: 0.0416 - val_acc: 0.9898
    Epoch 10/10
     - 3s - loss: 0.0378 - acc: 0.9883 - val_loss: 0.0435 - val_acc: 0.9898
    
    def show_train_history(train_history,train,validation):
        plt.plot(train_history.history[train])
        plt.plot(train_history.history[validation])
        plt.title('Train histiry')
        plt.ylabel(train)
        plt.xlabel('epoch')
        plt.legend(['train,','validation'],loc='upper left')
        plt.show()
    
    import matplotlib.pyplot as plt
    show_train_history(train_history,'acc','val_acc')
    

    在这里插入图片描述

    show_train_history(train_history,'loss','val_loss')
    

    在这里插入图片描述

    scores=model.evaluate(x_test4D,y_test_oneHot)
    print('accuracy=',scores[1])
    
    10000/10000 [==============================] - 1s 103us/step
    accuracy= 0.9906
    
    prediction=model.predict_classes(x_test4D)
    
    prediction
    
    array([7, 2, 1, ..., 4, 5, 6], dtype=int64)
    
    def plot_images_labels_prediction(images,labels,prediction,idx,num=10):
        flig=plt.figure(figsize=(12,14))
        if num>25:
            num=25
        for i in range(0,num):
            ax=plt.subplot(5,5,1+i)
            ax.imshow(images[idx],cmap='binary')
            title='labels='+str(labels[idx])
            if len(prediction)>0:
                title+=',predict='+str(prediction[idx])
            ax.set_title(title,fontsize=10)
            ax.set_xticks([])
            ax.set_yticks([])
            idx+=1
        plt.show()
    plot_images_labels_prediction(x_test_image,y_test_label,prediction,idx=0)
    

    在这里插入图片描述

    #混淆矩阵
    import pandas as pd
    pd.crosstab(y_test_label,prediction,rownames=['label'],colnames=['predict'])
    
    predict0123456789
    label
    0973100103110
    10113410000000
    23110220100410
    30001000030232
    4000097801003
    5101208833011
    6410012948020
    70262200101015
    8200111039633
    9141041111995
    df=pd.DataFrame({'label':y_test_label,'predict':prediction})
    
    print(df[(df.label==1) & (df.predict==2)])
    
          label  predict
    3073      1        2
    
    plot_images_labels_prediction(x_test_image,y_test_label,prediction,idx=3073,num=1)
    

    在这里插入图片描述

    好了,今天就到这里了,希望对学习理解有帮助,大神看见勿喷,仅为自己的学习理解,能力有限,请多包涵,侵删。

    展开全文
  • 目录 调用CNN模型,识别本地的手写数字图片 调用CNN模型,识别本地的手写数字图片 在实现实时识别手写数字之前先实现本地图片的识别,这里的本地图片是从画图里面自己手写导出的(手动设置为28*28大小的)。...
  • 实验CNN数字手写体识别基于python jupyter notebook android (可运行)可安装在手机.zip实验CNN数字手写体识别基于python jupyter notebook android (可运行)可安装在手机.zip实验CNN数字手写体识别基于python ...
  • 这一部分主要是实现手写数字识别模型的建立及保存。。
  • 利用pythorch 实现kaggle比赛中mnist的识别,准确率99+%,运用CNN MLP LSTM等多种方法,内含数据和文档,环境配置方法,代码有注释,解压后可直接运行,适合初学者!
  • 卷积神经网络经典案例,手写数字识别代码详解,注释之处如有错误,欢迎指正 from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf #初始化权重函数 def weight_variable(shape):...
  • 基于CNN的手写数字识别算法内容介绍算法原理实验环境实验步骤实验结果 内容介绍 卷积神经网络(Convolutional Neural Network,CNN) 卷积神经网络相较于传统的图像处理算法的优点之一在于避免了对图像复杂的前期...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 23,433
精华内容 9,373
关键字:

cnn数字识别