every blog every motto: You never know how strong you really are until being strong is the only choice you have。
0. 前言
查看Tensorflow2是使用GPU还是CPU小结
1. 正文
说明: 只要配置好GPU的驱动和cuda以及cudnn等工具,程序执行默认先使用GPU,如果不能执行再使用CPU
1.1 tensorflow 1.x
查看日志信息,若包含GPU信息,就是使用GPU
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
1.2 tensorflow 2.x
查看日志信息,若包含GPU信息,就是使用GPU
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import tensorflow as tf
sess = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))
参考文献
[1] https://blog.csdn.net/weixin_42702666/article/details/88067012
[2] https://zhuanlan.zhihu.com/p/110151684
[3] https://blog.csdn.net/qi_yue_yu/article/details/103549345?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase