美文网首页
解决 failed to allocate 4.67G (501

解决 failed to allocate 4.67G (501

作者: 博士伦2014 | 来源:发表于2018-12-03 12:24 被阅读0次

错误如下

failed to allocate 4.67G (5019415296 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
failed to allocate 4.21G (4517473792 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
failed to allocate 3.79G (4065726208 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
failed to allocate 3.41G (3659153408 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY

原因:没有指定GPU,导致内存不足
解决办法
第一步:需要指定GPU,代码头部添加如下代码:

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"

第二步:限制当前脚本可用显存,代码头部添加第一行,session 语句进行如第二行的修改

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

有时执行第一步后程序也可以正常运行

参考:

  1. https://blog.csdn.net/wangkun1340378/article/details/72782593
  2. https://blog.csdn.net/py496980138/article/details/78843217

相关文章

网友评论

      本文标题:解决 failed to allocate 4.67G (501

      本文链接:https://www.haomeiwen.com/subject/xjcycqtx.html