禁用gpu首选
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
config = tf.ConfigProto(allow_soft_placement=True)
config.gpu_options.per_process_gpu_memory_fraction =1 # 占用40%显存
# sess = tf.Session(config=config)
# with tf.Session() as sess:
with tf.Session(config=config) as sess:
with tf.Session() as sess:
with tf.device("/gpu:0"):
/gpu改成cpu