Unable to allocate 729. MiB for an array with shape (199, 400, 400, 3) and data type float64

說明

Unable to allocate 729. MiB for an array with shape (199, 400, 400, 3) and data type float64

在執行 tensorflow 遇到這樣的問題,大概猜測是記憶體存放已經滿載了,有幾個想法可以試試看去解決這個問題:

  1. 虛擬記憶體配置 : 是不是可以提高虛擬記憶體的容量 =>但是後來發現虛擬記憶體的容量也不能無止盡的放大,會導致系統不穩定。
  2. 解決的根本辦法 : 回到程式去看還是把程式中的記憶體釋放出來才是比較實在的。

操作流程

先去 google 看看這個問題有沒有相關的解法

google 搜尋

stack overflow : 使用超過造成的

有解法是 調整虛擬記憶體的容量=>調整方法

但要記得不能條超過大多調整範圍為實際的記憶體量三倍為最大值

Python 記憶體釋放

上面這個同時也是關鍵字,以這個丟去 google 搜尋

-參考記憶體釋放文章

import gc garbage collector
del a
gc.collect()

發現這個範例程式,使用 del 刪除變數,釋放空間,另外一的是 要引用 gc 這個包裹,這個是手動的方式去釋放記憶體

釋出記憶體後程式執行時的資源耗用

可以看到這個波形呈現一個周期性的,也就是每次回圈執行後釋出記憶體空間

參考

- [报错] [Ubuntu] [Python] MemoryError: Unable to allocate array with shape (x, x) and data type float64

留言