【发布时间】:2017-07-18 21:47:39
【问题描述】:
我正在尝试使用 scikit 提供的许多分类器来构建一个基本的字符识别模型。使用的数据集是一组标准的手写字母数字样本(Chars74K 图像数据集取自 source:EnglishHnd.tgz)。
每个字符有 55 个样本(总共 62 个字母数字字符),每个样本大小为 900x1200 像素。我正在将矩阵(首先转换为灰度)展平为 1x1080000 数组(每个数组代表一个特征)。
for sample in sample_images: # sample images is the list of the .png files
img = imread(sample);
img_gray = rgb2gray(img);
if n == 0 and m == 0: # n and m are global variables
n, m = np.shape(img_gray);
img_gray = np.reshape(img_gray, n*m);
img_gray = np.append(img_gray, sample_id); # sample id stores the label of the training sample
if len(samples) == 0: # samples is the final numpy ndarray
samples = np.append(samples, img_gray);
samples = np.reshape(samples, [1, n*m + 1]);
else:
samples = np.append(samples, [img_gray], axis=0);
所以最终的数据结构应该有 55x62 的数组,其中每个数组的容量为 1080000 个元素。只有最终的结构被存储(中间矩阵的范围是本地的)。
为学习模型而存储的数据量非常大(我猜),因为程序并没有真正超出某个点,并且使我的系统崩溃到必须修复 BIOS 的程度!
到目前为止,程序只是收集要发送给分类器的数据……分类甚至还没有被引入到代码中。
关于如何更有效地处理数据有什么建议吗?
注意:我使用 numpy 来存储展平矩阵的最终结构。 此外,该系统具有 8Gb RAM。
【问题讨论】:
标签: python arrays numpy classification ocr