TensorFlow 安装与环境配置

1、tf.config.set_visible_devices (devices=cpus) 设定似乎有问题,搜索了 Tf2 官方,也没看明白这个用法。

2、一种方法,类似于当前程序的全局设定,放在 import tensorflow 之前
import os
os.environ [“CUDA_DEVICE_ORDER”] = “PCI_BUS_ID”
os.environ [“CUDA_VISIBLE_DEVICES”] = “-1”

3,另一种方法,是程序临时指定
with tf.device (’/cpu:0’):
A = tf.constant ([[1, 2], [3, 4]])
B = tf.constant ([[5, 6], [7, 8]])
C = tf.matmul (A, B)
print ©

with tf.device (’/gpu:0’):
A = tf.constant ([[1, 2], [3, 4]])
B = tf.constant ([[5, 6], [7, 8]])
C = tf.matmul (A, B)
print ©