MemoryError:无法为形状为(1122、1122、12288)和数据类型float64

时间:2020-05-22 20:31:35

标签: python machine-learning computer-vision feature-extraction orb

我正在尝试传递一个返回平整的图像和标签数组的函数,而我的操作系统是Windows10。此外,当我尝试调用该函数i时,标题中所述的错误

MemoryError: Unable to allocate 115. GiB for an array with shape (1122, 1122, 12288) and data type float64

我想做的是:我想从一个函数内的关键点上提取数据集中的特征,并对我的数据集使用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)

1 个答案:

答案 0 :(得分:3)

函数在这里。您将所有平展图像附加到一个列表中,这会导致此内存错误。您可以使用dask数组存储它们.dask数组使用硬盘存储数据Dask是一个类似于Sparks的python库,专门用于大数据。