温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

解决TensorFlow GPU版出现OOM错误的问题

发布时间:2020-09-21 23:11:22 来源:脚本之家 阅读:1187 作者:lzher0 栏目:开发技术

问题:

在使用mask_rcnn预测自己的数据集时,会出现下面错误:

ResourceExhaustedError: OOM when allocating tensor with shape[1,512,1120,1120] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
 [[{{node rpn_model/rpn_conv_shared/convolution}} = Conv2D[T=DT_FLOAT, data_format="NCHW", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](fpn_p2/BiasAdd, rpn_conv_shared/kernel/read)]]
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.
 
 [[{{node roi_align_mask/strided_slice_17/_4277}} = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_3068_roi_align_mask/strided_slice_17", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
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.

原因:

一是、因为图片尺寸为3200*4480,图片的尺寸太大。

二是、我使用的是TensorFlow GPU版,而我GPU的显存只有8G,导致显存不够。

解决:

一是、将图片尺寸改小,小到占用的内存比显存。

二是、不使用GPU进行预测,只使用CPU预测,因为一般CPU内存要大于显存的。但装的又是GPU版的TensorFlow,所以需要在预测程序进行更改。

程序在前两行加入下面代码:

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

引号里填的是GPU的序号,不填的时候代表不使用GPU。

以上这篇解决TensorFlow GPU版出现OOM错误的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI