我在尝试传递一个返回扁平化图像和标签数组的函数,我的操作系统是Windows 10。此外,当我尝试调用该函数时,会出现标题中描述的错误
MemoryError: Unable to allocate 115. GiB for an array with shape (1122, 1122, 12288) and data type float64
我想做的是:我想从带有关键点的DataSet中提取特征,并在函数中使用train_test_split处理我的数据集,但即使我尝试扁平化带有关键点的图像,也会得到这个错误,唯一能扁平化的方式是没有关键点的相同图像。
我尝试的方法如下:
def load_image_files(fullpath, dimension=(35, 35)):
flat_data = []
orb = cv2.ORB_create(edgeThreshold=1, nfeatures=22)
key_points = [cv2.KeyPoint(64, 9, 10),
cv2.KeyPoint(107, 6, 10),
cv2.KeyPoint(171, 10, 10)]
kp, des = orb.compute(imageList, key_points)
kparray = cv2.drawKeypoints(imageList, kp, None, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS);
img_resized = resize(kparray, dimension, anti_aliasing=True, mode='reflect')
img_resized = img_resized.flatten()
flat_data.append(img_resized)
images.append(flat_data)
flat_data = np.array(flat_data)
images = np.array(images)
return Bunch(data=flat_data,
images=images)
回答:
在您的函数中,您将所有扁平化的图像追加到一个列表中,这导致了内存错误。相反,您可以使用dask数组来存储它们。dask数组使用硬盘来存储那些太大而无法装入内存的数据。dask是一个类似于sparks的Python库,专为大数据设计。