如果你今天訓練時候需要無窮迴圈

就是特定條件才停止

可能會用到

 

training_loader_cyc = itertools.cycle(self.training_loader)

 

但是這樣會導致記憶體爆炸

產生類似

 

[警告] 讀取失敗(1/3):cache\263_pet_ub_ac__ALL_lymphoma_seg-e0-s54.mat, error: Unable to allocate output buffer. [警告] 讀取失敗(1/3):cache\299_pet_ub_ac__ALL_lymphoma_seg-e0-s40.mat, error: Unable to allocate output buffer. [警告] 讀取失敗(1/3):cache\299_pet_ub_ac__ALL_lymphoma_seg-e0-s97.mat, error: Unable to allocate output buffer. [警告] 讀取失敗(2/3):cache\299_pet_ub_ac__ALL_lymphoma_seg-e0-s97.mat, error:

這種記憶體不足的錯誤

 

 

原因是 cycle 會把整個 iterable 的結果都緩存在內部 list 裡,也就是它會把每個 batch 的資料都「記住」,以便下一輪循環

天啊~~~

 

原來會有這個問題

這邊註記一下...