强制tensorflow使用cpu

one-----------------start-------------

 

import tensorflow as tf
cpu=tf.config.list_physical_devices("CPU")
tf.config.set_visible_devices(cpu)
print(tf.config.list_logical_devices())


one-----------------end-------------

 

two-----------------start-------------

import os
os.environ["CUDA_VISIBLE_DEVICES"]="-1"
import tensorflow as tf
print(tf.config.list_logical_devices())


two-----------------end-------------

posted @ 2026-01-09 14:59  滑板拉半挂  阅读(4)  评论(0)    收藏  举报