python - 简单(有效)手写数字识别: how to improve it?

标签 python math ocr data-analysis svd

我刚刚写了这个非常简单的手写数字识别。 Here is 8kb archive使用以下代码 + 十个 .PNG 图像文件。它有效:enter image description here被广泛认为是enter image description here .

简而言之,数据库的每个数字(50x50 像素 = 250 个系数)被汇总为一个 10 系数向量(通过保留 10 个最大奇异值,请参阅 Low-rank approximation with SVD )。

然后,为了识别该数字,我们最小化与数据库中的数字的距离。

from scipy import misc
import numpy as np
import matplotlib.pyplot as plt

digits = []
for i in range(11):
    M = misc.imread(str(i) + '.png', flatten=True)
    U, s, V = np.linalg.svd(M, full_matrices=False)
    s[10:] = 0        # keep the 10 biggest singular values only, discard others
    S = np.diag(s)
    M_reduced = np.dot(U, np.dot(S, V))      # reconstitution of image with 10 biggest singular values
    digits.append({'original': M, 'singular': s[:10], 'reduced': M_reduced})

# each 50x50 pixels digit is summarized into a vector of 10 coefficients : the 10 biggest singular values s[:10]    

# 0.png to 9.png = all the digits (for machine training)
# 10.png = the digit to be recognized
toberecognizeddigit = digits[10]    
digits = digits[:10]

# we find the nearest-neighbour by minimizing the distance between singular values of toberecoginzeddigit and all the digits in database
recognizeddigit = min(digits[:10], key=lambda d: sum((d['singular']-toberecognizeddigit['singular'])**2))    

plt.imshow(toberecognizeddigit['reduced'], interpolation='nearest', cmap=plt.cm.Greys_r)
plt.show()
plt.imshow(recognizeddigit['reduced'], interpolation='nearest', cmap=plt.cm.Greys_r)
plt.show()

问题:

代码可以运行(您可以运行 ZIP 存档中的代码),但是我们如何改进它以获得更好的结果?(我认为主要是数学技巧)。

例如,在我的测试中,9 和 3 有时会相互混淆。

最佳答案

数字识别可能是一个相当困难的领域。特别是当数字以非常不同或不清楚的方式书写时。为了解决这个问题,人们采取了很多方法,整个比赛都致力于这个主题。有关示例,请参阅Kaggle's digit recognizer competition 。本次比赛基于众所周知的MNIST data set 。在那里的论坛中,您会发现很多解决此问题的想法和方法,但我会给出一些快速建议。

很多人将这个问题视为分类问题。解决此类问题的可能算法包括 kNN、神经网络或梯度提升等。

但是,通常仅靠算法不足以获得最佳分类率。提高分数的另一个重要方面是特征提取。这个想法是计算能够区分不同数字的特征。该数据集的一些示例特征可能包括彩色像素的数量,或者可能是数字的宽度和高度。

尽管其他算法可能不是您正在寻找的算法,但添加更多功能也可能可以提高您当前使用的算法的性能。

关于python - 简单(有效)手写数字识别: how to improve it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34116526/

相关文章:

java - 在 Android 中将位图传递给 Tesseract

ocr - OCR 软件能否可靠地从表格中读取值?

python - 如何通过检查从 CSV 文件中删除重复项?

python - 使用Python进行杰卡德距离的非对称计算

python - 具有对数 Y 轴的小平面网格上的线性回归线

javascript - 确定图像在矩形内的最大可能尺寸

java - 在给定范围内生成奇数随机数

javascript - 如何旋转矢量?

python - 使用 MNIST 数据集训练的 NN 和 CNN 数字识别前的预处理

python - 如何从 bash 中的 python 脚本的一组不同输入文件中输出多个文件