【发布时间】: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