解決TensorFlow GPU版出現(xiàn)OOM錯誤的問題
問題:
在使用mask_rcnn預(yù)測自己的數(shù)據(jù)集時,會出現(xiàn)下面錯誤:
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,導(dǎo)致顯存不夠。
解決:
一是、將圖片尺寸改小,小到占用的內(nèi)存比顯存。
二是、不使用GPU進行預(yù)測,只使用CPU預(yù)測,因為一般CPU內(nèi)存要大于顯存的。但裝的又是GPU版的TensorFlow,所以需要在預(yù)測程序進行更改。
程序在前兩行加入下面代碼:
import os os.environ["CUDA_VISIBLE_DEVICES"] = ""
引號里填的是GPU的序號,不填的時候代表不使用GPU。
以上這篇解決TensorFlow GPU版出現(xiàn)OOM錯誤的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python Web框架Flask中使用新浪SAE云存儲實例
這篇文章主要介紹了Python Web框架Flask中使用新浪SAE云存儲實例,本文是對SAE云存儲的簡單封裝,需要的朋友可以參考下2015-02-02