tensorflow 制定 CPU 或GPU

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luoganttcc/article/details/82915152

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)

猜你喜欢

转载自blog.csdn.net/luoganttcc/article/details/82915152