环境:python3.6+tensorflow==2.0+keras2.3.1
方法一:
import tensorflow as tf
import keras.backend.tensorflow_backend as KTF
KTF.set_session(tf.Session(config=tf.ConfigProto(device_count={'gpu':0})))
这里在tensorflow2.0中肯定报错
修改如下:
import tensorflow as tf
import keras.backend.tensorflow_backend as KTF
KTF.set_session(tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(device_count={'gpu':0})))
然而这样还是不行,就是告诉你tensorflow2.0中不能这样用
遂放弃
方法二
CUDA_VISIBLE_DEVICES=0 python3 xxx.py
貌似可行