Python keras在拟合模型时是否深度复制数据?

Python keras在拟合模型时是否深度复制数据?,python,tensorflow,memory,keras,deep-learning,Python,Tensorflow,Memory,Keras,Deep Learning,当我运行我的模型(用于图像分割的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_i

当我运行我的模型(用于图像分割的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是否在深度复制数据,如果是这样的话,是否有办法避免它(不使用数据生成器)

主脚本:

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检查这篇文章它将帮助您解决数据生成问题检查这篇文章它将帮助您解决数据生成问题我不想使用数据生成器(我想避免在两个时代之间计算数据)如我的问题中所述,+you链接显示了数据生成器与fit_generator的不推荐使用。我不想使用数据生成器(我想避免计算历元之间的数据),如我的问题中所述,+you链接显示了数据生成器与fit_generator的不推荐使用。可以制作的唯一数据副本是到GPU,但这是成批发生的。在任何情况下,这些消息都不是错误,只是警告。唯一可以复制到GPU的数据,但这是成批发生的。在任何情况下,这些消息都不是错误,只是警告。