tensorflow 内存错误

使用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.

把下述代码贴到训练完成后

python 复制代码
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()
相关推荐
云程笔记3 小时前
004.环境搭建基础篇:Python、CUDA、cuDNN、PyTorch/TensorFlow安装与版本兼容性踩坑
pytorch·python·tensorflow
HIT_Weston8 小时前
45、【Agent】【OpenCode】本地代理分析(请求&接收回调)
人工智能·agent·opencode
知行合一。。。8 小时前
Python--04--数据容器(总结)
开发语言·python
架构师老Y8 小时前
008、容器化部署:Docker与Python应用打包
python·容器·架构
逻辑君8 小时前
认知神经科学研究报告【20260010】
人工智能·深度学习·神经网络·机器学习
星河耀银海8 小时前
远控体验分享:安全与实用性参考
人工智能·安全·微服务
lifewange8 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
企业架构师老王9 小时前
2026企业架构演进:科普Agent(龙虾)如何从“极客玩具”走向实在Agent规模化落地?
人工智能·ai·架构
GreenTea9 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
pluvium279 小时前
记对 xonsh shell 的使用, 脚本编写, 迁移及调优
linux·python·shell·xonsh