兩者同時存在時使用gpu
要想使用cpu,在代碼裏添加如下命令:
matrix1=tf.constant([[3.,3.]])
matrix2=tf.constant([[2.],[2.]])
with tf.Session() as ses:
with tf.device("/cpu:0"):
product=tf.matmul(matrix1,matrix2)
說明一下:
“/cpu:0” The CPU of your machine
“/gpu:0” The GPU of yout machine ,if you have one
如果要換成gpu的話,照着改可以了
或
os.environ[“CUDA_VISIBLE_DEVICES”] = "-1"
一行即可