例えば、使用するメモリを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))