使用cnn做手写数字识别_使用CNN分类的手写数字识别(过程说明)

使用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

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CNN(卷积神经网络)是一种用于图像分类的深度学习模型。通过卷积层、池化层和全连接层的组合,CNN能够从输入的图像中提取特征并进行分类。下面是一个简单的CNN分类代码示例: 首先,导入必要的库和模块,如tensorflow和keras: import tensorflow as tf from tensorflow import keras 接下来,定义CNN模型。可以使用Sequential类来顺序地构建模型,也可以使用Functional API进行更灵活的模型定义。在本例中,我们使用Sequential类: model = keras.Sequential() 添加卷积层和池化层: model.add(keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu', input_shape=(28, 28, 1))) # 输入图像大小为28x28,通道数为1 model.add(keras.layers.MaxPooling2D(pool_size=(2, 2))) 继续添加卷积层和池化层: model.add(keras.layers.Conv2D(filters=64, kernel_size=3, activation='relu')) model.add(keras.layers.MaxPooling2D(pool_size=(2, 2))) 添加全连接层: model.add(keras.layers.Flatten()) model.add(keras.layers.Dense(units=128, activation='relu')) model.add(keras.layers.Dense(units=10, activation='softmax')) # 输出层,10个类别 编译模型: model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) 训练模型: model.fit(train_images, train_labels, epochs=10, batch_size=64) 其中train_images是训练图像的集合,train_labels是相应的类别标签。 最后,使用测试数据对模型进行评估: test_loss, test_acc = model.evaluate(test_images, test_labels) 以上就是一个基本的CNN分类代码。通过构建深层的卷积神经网络,利用不同的卷积核和池化操作,CNN能够自动提取图像的特征,并应用于分类任务中。该模型能够有效地处理图像数据,并取得较好的分类性能。 ### 回答2: CNN(卷积神经网络)是一种在图像识别和处理领域广泛应用的深度学习模型。CNN模型的分类C代码可以涵盖网络结构的定义、数据预处理、模型的训练和推理过程。 首先,我们需要定义CNN网络结构。这可以通过使用诸如Keras或PyTorch等深度学习框架的API来完成。我们可以通过堆叠多个卷积层、池化层和全连接层来定义CNN模型的结构,并使用合适的激活函数和正则化方法来优化模型的性能。 其次,数据预处理是非常重要的一步。我们需要将图像数据转换为模型可接受的格式。这可能包括将图像缩放为固定大小、将像素值归一化到特定范围、进行数据增强等操作。这样可以增强模型的泛化能力,并减少过拟合的风险。 然后,我们可以开始训练模型。我们可以使用反向传播算法来更新模型的参数,以使其能够更好地对训练数据进行分类。我们可以指定损失函数来衡量模型在训练期间的性能,并选择适当的优化算法来最小化损失函数。通过迭代训练过程,模型的准确性将不断提高。 最后,我们可以使用训练好的模型进行推理。通过将新的图像数据输入到模型中,我们可以得到预测的类别标签。这可以通过使用模型的前向传播方法来实现,根据输出的概率分布进行分类决策。 综上所述,CNN分类C代码可以根据具体需求来编写。它包括定义网络结构、数据预处理、模型训练和推理过程。通过调整和优化这些步骤,我们可以训练出强大的CNN模型,用于图像分类和其他相关任务。 ### 回答3: CNN(卷积神经网络)是一种广泛应用于图像识别和计算机视觉领域的机器学习模型。下面是一个示例的CNN分类C语言代码: ```c #include <stdio.h> #include <stdlib.h> // 定义CNN结构体 typedef struct { int numFilters; // 卷积层滤波器的数量 int filterSize; // 卷积层滤波器的尺寸 int imageSize; // 输入图像的尺寸 float** filters; // 卷积层滤波器的权重矩阵 } CNN; // 初始化CNN CNN* initializeCNN(int numFilters, int filterSize, int imageSize) { CNN* cnn = (CNN*)malloc(sizeof(CNN)); cnn->numFilters = numFilters; cnn->filterSize = filterSize; cnn->imageSize = imageSize; // 初始化滤波器权重矩阵 cnn->filters = (float**)malloc(numFilters * sizeof(float*)); for (int i = 0; i < numFilters; i++) { cnn->filters[i] = (float*)malloc(filterSize * filterSize * sizeof(float)); for (int j = 0; j < filterSize * filterSize; j++) { cnn->filters[i][j] = (float)rand() / RAND_MAX; // 随机初始化权重值 } } return cnn; } // CNN分类函数 int classifyCNN(CNN* cnn, float** image) { // 卷积运算 float** result = (float**)calloc(cnn->numFilters, sizeof(float*)); for (int i = 0; i < cnn->numFilters; i++) { result[i] = (float*)calloc(cnn->imageSize - cnn->filterSize + 1, sizeof(float)); for (int j = 0; j < cnn->imageSize - cnn->filterSize + 1; j++) { for (int k = 0; k < cnn->imageSize - cnn->filterSize + 1; k++) { for (int m = 0; m < cnn->filterSize; m++) { for (int n = 0; n < cnn->filterSize; n++) { result[i][j] += image[j + m][k + n] * cnn->filters[i][m * cnn->filterSize + n]; } } } } } // 池化运算 float* pooledResult = (float*)calloc(cnn->numFilters, sizeof(float)); for (int i = 0; i < cnn->numFilters; i++) { pooledResult[i] = result[i][0]; for (int j = 1; j < cnn->imageSize - cnn->filterSize + 1; j++) { if (result[i][j] > pooledResult[i]) { pooledResult[i] = result[i][j]; } } } // 选择最大池化结果作为分类结果 int maxIndex = 0; for (int i = 1; i < cnn->numFilters; i++) { if (pooledResult[i] > pooledResult[maxIndex]) { maxIndex = i; } } return maxIndex; } int main() { int numFilters = 5; int filterSize = 3; int imageSize = 5; // 构造一个3x3的示例图像 float** image = (float**)malloc(imageSize * sizeof(float*)); for (int i = 0; i < imageSize; i++) { image[i] = (float*)malloc(imageSize * sizeof(float)); for (int j = 0; j < imageSize; j++) { image[i][j] = (float)rand() / RAND_MAX; // 随机初始化像素值 } } // 初始化CNN CNN* cnn = initializeCNN(numFilters, filterSize, imageSize); // 分类图像 int classIndex = classifyCNN(cnn, image); // 打印分类结果 printf("The image is classified as class %d.\n", classIndex); // 释放内存 for (int i = 0; i < imageSize; i++) { free(image[i]); } free(image); for (int i = 0; i < numFilters; i++) { free(cnn->filters[i]); } free(cnn->filters); free(cnn); return 0; } ``` 上述代码演示了一个使用CNN对图像进行分类的示例。首先,我们定义了一个CNN结构体,其中包含卷积层的滤波器数量、滤波器尺寸以及输入图像尺寸等参数。接着,我们初始化了CNN并随机初始化了滤波器的权重值。然后,我们通过卷积运算和池化运算得到了每个滤波器的池化结果,并选择最大池化结果作为分类结果。最后,打印出了分类结果并进行了内存释放。 这只是一个简单的CNN分类C代码示例,实际上,CNN还可以进行更深层次的卷积和池化运算,以及更加复杂的网络结构和训练过程

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值