使用tensorflow训练多个模型时,训练过程中容易出现内存错误,在这里记录一下解决办法。希望能帮到各位。
2025-01-02 22:31:03.489713: W tensorflow/core/common_runtime/bfc_allocator.cc:275] Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.41GiB with freed_by_count=0. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
把下述代码贴到训练完成后
import tensorflow.keras.backend as K
import gc
import tensorflow as tf
#训练完成后
CNN2_Unet = None
tf.compat.v1.reset_default_graph()
K.clear_session()
gc.collect()