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)
posted @ 2018-10-01 10:17  luoganttcc  阅读(92)  评论(0编辑  收藏  举报