tensorflow 制定 CPU 或GPU
CPU
with tf.Session() as sess:
...: with tf.device("/cpu:0"):
...: m1=tf.constant([[3,3]])
...: m2=tf.constant([[2],[2]])
...: product=tf.matmul(m1,m2)
...: result=sess.run(product)
...: print(result)
GPU
with tf.Session() as sess:
...: with tf.device("/gpu:0"):
...: m1=tf.constant([[3,3]])
...: m2=tf.constant([[2],[2]])
...: product=tf.matmul(m1,m2)
...: result=sess.run(product)
...: print(result)