首页 > 解决方案 > 在 Python 中加载数据集时内核死机:为什么会这样?

问题描述

我正在尝试在 Python 中加载 7000 个 .mat 文件的数据集作为 7000-d 张量,每个条目的形状为 100 x 100 x 100 x 3。整个数据集小于 80 MB。我正在使用 Spyder。代码如下

dataDir = "/Users/..."
data= []
x_train = np.empty([7165, 100*100*100*3])
x_train = x_train.reshape([7165, 100, 100, 100, 3])

i = 0;

for file in sorted_alphanumeric(os.listdir( dataDir )):
    data = scipy.io.loadmat( dataDir+file )   #store data as LIST
    x_train[i] = np.array(data['tensor'])
    i = i + 1

然而,在读取了大约 2300 行之后,内核死了,程序停止运行。为什么内核会死?如何存储数据集?在我看来,数据集并没有那么大,控制台中的“内存”键总是在 76% 左右。

标签: pythonscipydatasetspyder

解决方案


7000x100x100x100 = 7,000,000,000 是太多的内存,即使在位 7 000 000 000 * 3 位 = 2.62500 GB中也无法处理


推荐阅读