LoginSignup
10
11

More than 3 years have passed since last update.

Tensorflowで使用するGPUのメモリを制限したいとき

Posted at

例えば、使用するメモリをGPUが持つメモリ容量の半分=50%に制限したいとする
このとき、

import tensorflow as tf
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))

のように書くと、

module 'tensorflow' has no attribute 'GPUOptions'

のようなエラーが出た。なぜ・・・

どうやら、Tensorflow2.0にはこれらのGPUに関するモジュールがなくなったらしい。(なんで消すねん)
そこで、

tf.ConfigProto

tf.compat.v1.ConfigProto
置き換えればTensorflow1.0を使用することができる。

したがって、以下のように書けば動く
gpu_options = tf.compat.v1.GPUOptions(per_process_gpu_memory_fraction=0.5)
sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(gpu_options=gpu_options))

10
11
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
10
11