【问题标题】:Kernel died when loading a dataset in Python: why does it happen?在 Python 中加载数据集时内核死机:为什么会这样?
【发布时间】:2021-01-11 20:38:09
【问题描述】:

我正在尝试在 Python 中将 7000 个 .mat 文件的数据集加载为 7000 维张量,每个条目的形状为 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% 左右。

【问题讨论】:

    标签: python scipy dataset spyder


    【解决方案1】:

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

    【讨论】:

    • 但我确信人们会处理更大的数据集?那我怎样才能在 Python 上加载它呢?
    【解决方案2】:

    不要一次加载整个数据集,以免内存不足。即使使用 Google Colab 等在线工具并将数据集划分为多个部分,也无法避免这种情况。
    处理大数据集的方法是通过批量训练(即通过一次加载批量数据集来训练模型)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      • 2021-06-04
      • 2021-11-22
      • 2014-12-21
      • 2019-06-01
      • 2020-10-26
      相关资源
      最近更新 更多