1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GPUのメモリ使い果たし対策(tensorflow version2.0)

Last updated at Posted at 2019-12-23

GPUのメモリ節約法(tensorflow)

こんにちは、にわかです。

テーマは、タイトル通りなのですが、GPUのメモリ(VRAM)使い果たし対策です。

初期化時のGPUのメモリ確保を制限する。

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
  try:
    for gpu in gpus:
        tf.config.experimental.set_memory_growth(gpu, True) 
  except RuntimeError as e:
    print(e)

バッチサイズを1つにしたのに、画像の縦横の大きさを小さくしたのに、メモリの使い果たしをした人は上の方法で解決できるはずです。

※プログラムの開始時に、GPUのメモリを確保できるだけ確保するため(何かしらのプロセス用に)、後から学習データをGPUにロードする際にメモリの使い果たしで、ランタイムエラーを起こす場合があります。上のコードを書けば、必要になった分だけGPUのメモリ確保を行います。

ちなみに、CPUには上のコード使えないので注意してください。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?