【问题标题】:Is keras deep copying data when fitting the model?keras在拟合模型时是否深度复制数据?
【发布时间】:2021-03-02 17:48:45
【问题描述】:

当我运行我的模型(用于图像分割的 Unet)时,我会弹出 ram 内存错误:

2020-11-19 11:25:18.027748: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 11998593024 exceeds 10% of free system memory.
2020-11-19 11:25:32.991088: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 11998593024 exceeds 10% of free system memory.
2020-11-19 11:25:46.109554: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 11998593024 exceeds 10% of free system memory.

分配的内存图:

我想知道 tensorflow 是否在深度复制数据,如果是,有没有办法避免它(不使用 DataGenerator)。

主脚本:

from data_preprocessing import data_utils,DataGenerator
from model import model_utils,loss_utils
from keras.callbacks import ModelCheckpoint, LearningRateScheduler
from sklearn.model_selection import train_test_split
import tensorflow as tf

if __name__ == "__main__":
    X,Y = data_utils.load_all()
    print("Checkpoint 1")
    strategy = tf.distribute.MirroredStrategy()
    with strategy.scope():
        Xtrain,Xtest,Ytrain,Ytest = train_test_split(X,Y, test_size = 1/5, shuffle = True)
        print("Checkpoint 2")
        unet = model_utils.unet(input_size=(256,256,1))
        print("Checkpoint 3")
        checkpointer = ModelCheckpoint('image_segm.hdf5',monitor='loss',verbose=1,save_best_only=True)
        historic = unet.fit(Xtrain,Ytrain,epochs=1,callbacks=[checkpointer],batch_size= 5)
        print("End")

编辑:在 conda 环境中使用 tensorflow-gpu 2.20.0

【问题讨论】:

  • 唯一可以制作的数据副本是到 GPU,但这是分批进行的。在任何情况下,这些消息都不是错误,只是警告。

标签: python tensorflow memory keras deep-learning


【解决方案1】:

查看这篇文章,它将帮助您解决 Datagen 问题https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly

【讨论】:

  • 我不想使用 DataGenerators(我想避免在 epochs 之间计算数据),正如我的问题中所述 + 你的链接显示不推荐使用 fit_generator 的数据生成器。
猜你喜欢
  • 2021-10-02
  • 1970-01-01
  • 2021-08-12
  • 2018-08-30
  • 2020-05-12
  • 1970-01-01
  • 2020-09-12
  • 1970-01-01
  • 2019-09-14
相关资源
最近更新 更多