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()
相关推荐
一点一木36 分钟前
🚀 2026 年 6 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
aneasystone本尊37 分钟前
学习 turbovec 的 SIMD 搜索内核
人工智能
阳光是sunny10 小时前
别再被 worktree 绕晕了!AI 编程时代你必须掌握的 Git 隔离神器
前端·人工智能·后端
冬奇Lab10 小时前
每日一个开源项目(第148篇):obsidian-skills - Obsidian CEO 亲写的 AI Agent 格式规范,让 Agent 不再破坏你的 Vault
人工智能·开源·资讯
ethantan10 小时前
AI Agent 组成:像人一样思考的智能体
人工智能·程序员·架构
冬奇Lab10 小时前
Workflow 系列(05):评测体系——三层测试结构与 Trace 追踪
人工智能·工作流引擎
ethantan11 小时前
一篇讲解AI Agent 组成:像人一样思考的智能体
人工智能·后端·程序员
apocelipes13 小时前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
Cosolar13 小时前
vLLM 生产级部署完全指南
人工智能·后端·架构
CodePlayer竟然被占用了13 小时前
被美国政府封杀18天,Claude Fable 5 回来了——但代价是什么?
人工智能