首页 > 其他 > 详细

解决重复运行Tensorflow程序GPU内存占用的小白方法

时间:2020-08-01 21:47:37      阅读:277      评论:0      收藏:0      [点我收藏+]

作为一个刚入门CV的新手,最近在运行一个生成人脸图像的程序时遇到了问题,程序是可以运行的,但是运行两次后就会出错,具体如下:

ResourceExhaustedError: 2 root error(s) found.
  (0) Resource exhausted: OOM when allocating tensor with shape[1,3,3,512,512] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
     [[{{node G_synthesis_5/_Run/G_synthesis/64x64/Conv0_up/Square}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

     [[G_synthesis_5/_Run/saturate_cast/_4577]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

  (1) Resource exhausted: OOM when allocating tensor with shape[1,3,3,512,512] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
     [[{{node G_synthesis_5/_Run/G_synthesis/64x64/Conv0_up/Square}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

0 successful operations.
0 derived errors ignored.

先介绍下我的运行环境:

  • Win 10
  • Spyder
  • Tensorflow-GPU == 1.14.0

查到的原因是GPU显存不够了。

技术分享图片

 

第一次运行,专用GPU内存:0 ===> 1.2,第二次运行:1.2 ===> 1.6,第三次就没有办法运行了,由于自己的电脑是渣渣显卡,显存太小,而我的程序是需要不断改变参数重复运行的,但网上查了一遍说显存是不会运行一次就释放资源的,所以我不得不每运行两次就重启Spyder这样来释放显存。也尝试过运行一次后就杀掉显卡中的这个程序,但结果是直接导致Spyder内核连接中断,结果还是重启。

最后,灵机一动,直接在控制台重启内核就可以释放掉程序以及所占显存资源,这样就不用重启麻烦了。

如果是一段连续程序显存不够,那就要么换大一点显存的显卡,或者设置每次占用GPU资源的值了。这个可以看看其他博主的博客。

方法不高级,但挺实用,如果有更好的方法,欢迎留言评论。

解决重复运行Tensorflow程序GPU内存占用的小白方法

原文:https://www.cnblogs.com/MK-XIAOYU/p/13415766.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!