我是靠谱客的博主 执着鲜花,最近开发中收集的这篇文章主要介绍解决TensorFlow GPU版出现OOM错误,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

问题:

在使用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错误的全部内容,希望文章能够帮你解决解决TensorFlow GPU版出现OOM错误所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部