在安装好tensorflow及其相关部件后,我们可以通过以下方法去检测Tensorflow是否成功调用了GPU。
目录
本人配置注明:
检测Tensorflow是否调用GPU
方法一
方法二
本人配置注明:
本人tensorflow、CuDA等部件版本如下:
Tensorflow 2.7.0
Python 3.7.11
关于各部件版本对应问题,我会尽快发帖说明。
检测Tensorflow是否调用GPU
方法一
输入以下命令:
import tensorflow.compat.v1 as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
[!!!此处需要 import tensorflow.compat.v1 as tf 。如果直接 import tensorflow as tf,则会报错'AttributeError: module 'tensorflow' has no attribute 'Session' ']
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2023-03-03 13:20:44.274717: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-03-03 13:20:45.877778: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2023-03-03 13:20:54.015703: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2023-03-03 13:21:04.540028: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2023-03-03 13:25:34.047020: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2023-03-03 13:25:34.047944: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2023-03-03 13:26:04.474123: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2023-03-03 13:27:33.161191: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
方法二
输入以下命令:
import tensorflow as tf
print(tf.test.is_gpu_available())
若结果返回为True,则显示GPU可用。
文章来源:https://www.toymoban.com/news/detail-438139.html
以上仅个人在配置使用Tensorflow过程中所作总结,希望对大家有用。文章来源地址https://www.toymoban.com/news/detail-438139.html
到了这里,关于检测安装Tensorflow后是否成功调用GPU的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!