作為一個剛入門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資源的值了。這個可以看看其他博主的博客。
方法不高級,但挺實用,如果有更好的方法,歡迎留言評論。