目录

1.查看当前Tensorflow版本
2.查看当前主机运行的设备
3.查看GPU是否可用,指定在CPU/GPU运行
4.比较CPU和GPU上的运行时间

1.查看当前Tensorflow版本

import tensorflow as tf
print(tf.__version__)

会得到自己的tensorflow的版本号

2.查看当前主机运行的设备

import tensorflow as tfgpus = tf.config.experimental.list_physical_devices(device_type='GPU')
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
print(gpus)
print(cpus)

3.查看GPU是否可用,指定在CPU/GPU运行

import tensorflow as tf# 指定在cpu上运行
with tf.device('/cpu:0'):cpu_a = tf.random.normal([10000, 1000])cpu_b = tf.random.normal([1000, 2000])cpu_c = tf.matmul(cpu_a, cpu_b)
print("cpu_a:", cpu_a.device)
print("cpu_b:", cpu_b.device)
print("cpu_c:", cpu_c.device)
# 查看gpu是否可用
print(tf.config.list_physical_devices('GPU'))
# 指定在gpu上运行
with tf.device('/gpu:0'):gpu_a = tf.random.normal([10000, 1000])gpu_b = tf.random.normal([1000, 2000])gpu_c = tf.matmul(gpu_a, gpu_b)
print("gpu_a:", gpu_a.device)
print("gpu_b:", gpu_b.device)
print("gpu_c:", gpu_c.device)

4.比较在CPU和GPU上的运行时间

import tensorflow as tf
import timeitdef cpu_run():with tf.device('/cpu:0'):cpu_a = tf.random.normal([10000, 1000])cpu_b = tf.random.normal([1000, 2000])c = tf.matmul(cpu_a, cpu_b)return cdef gpu_run():with tf.device('/gpu:0'):gpu_a = tf.random.normal([10000, 1000])gpu_b = tf.random.normal([1000, 2000])c = tf.matmul(gpu_a, gpu_b)return ccpu_time = timeit.timeit(cpu_run, number=10)
gpu_time = timeit.timeit(gpu_run, number=10)
print("cpu:", cpu_time, "  gpu:", gpu_time)

TensorFlow测试CPU、GPU相关推荐

  1. win10和Ubuntu16.04中基于anaconda安装TensorFlow(CPU+GPU)

    目录 Windows系统下安装步骤 安装CPU版本的tensorflow 安装GPU版本的tensorflow(使用GPU加速的tensorflow模型训练速度更快) Ubuntu中的安装步骤 安装C ...

  2. Tensorflow + PyTorch 安装(CPU + GPU 版本)

    目录 一.Anaconda 安装 二.安装 TensorFlow-CPU 1.配置环境 2.安装 Tensorflow 三.安装TensorFlow-GPU 1.是否可安装GPU版Tensorflow ...

  3. Win10快速搭建Tensorflow(CPU/GPU)

    Win10快速搭建Tensorflow 如果需要详细的安装介绍请看:安装详解 一.快速搭建过程: 第一步:下载Anaconda,并安装. Anaconda官网下载地址:https://www.anac ...

  4. TensorFlow指定CPU和GPU方法

    TensorFlow指定CPU和GPU方法 TensorFlow 支持 CPU 和 GPU.它也支持分布式计算.可以在一个或多个计算机系统的多个设备上使用 TensorFlow. TensorFlow ...

  5. tensorflow 使用CPU而不使用GPU的问题解决

    tensorflow 使用CPU而不使用GPU的问题解决 参考文章: (1)tensorflow 使用CPU而不使用GPU的问题解决 (2)https://www.cnblogs.com/hutao7 ...

  6. tensorflow 制定 CPU 或GPU

    tensorflow 制定 CPU 或GPU CPU with tf.Session() as sess:...: with tf.device("/cpu:0"):...: m1 ...

  7. 成功解决:Win系统下的Tensorflow使用CPU而不使用GPU运行加速

    成功解决:Win系统下的Tensorflow使用CPU而不使用GPU运行加速 目录 解决问题 解决思路 解决方法 解决问题 Win系统下的Tensorflow使用CPU而不使用GPU运行加速 解决思路 ...

  8. 指定tensorflow运行的GPU或CPU设备

    如果 TensorFlow 指令中兼有 CPU 和 GPU 实现,当该指令分配到设备时,GPU 设备有优先权. 如果你的系统里有多个 GPU, 那么 ID 最小的 GPU 会默认使用. 当我们要指定t ...

  9. Window10 NVIDIA显卡 Tensorflow 2.1 GPU 安装和测试

    Window10 NVIDIA显卡 Tensorflow 2.1 GPU 安装和测试 1. 硬件要求 支持以下带有 GPU 的设备: CUDA® 计算能力为 3.5 或更高的 NVIDIA® GPU ...

最新文章

  1. 【源码分享】用Java写的网页图片、CSS、JavaScript分类下载器
  2. JSON数据和Java对象的相互转换
  3. SQL syntax-log2
  4. linux服务器报Too many open files的解决方法
  5. Linux安装SNMP
  6. 计算机系统基础:计算机可靠性知识笔记
  7. php 构造骚扰短信发送机(仅供学习与参考,请勿用于非法用途)
  8. 精华Java问题总结
  9. 如何在本地搭建svn本地版本库
  10. NAACL’21 | 来看如何让模型学会因为所以但是如果
  11. 深度学习-TF函数-layers.concatenate用法
  12. 成为一名架构师得学习哪些知识?
  13. python和c先学哪个-对于初学者而言,python和 c语言先学哪个好
  14. SLAM 领域国内外优秀实验室/开源方案(汇总)
  15. java交接文档_如何写好交接文档
  16. linux下nginx和redis安装笔记
  17. 射频能量用于治疗和美容
  18. 计算机应用基础题库及答案
  19. Excel如何一次性显示所有隐藏工作表
  20. 使用Windows驱动的虚拟打印机,打印Excel表格无表格线问题解决(1)

热门文章

  1. 不要以分期付款的方式结婚
  2. Java经典面试题详解:抖音Java后端123面开挂
  3. [IMX6DL][Android4.4] 超声波模块KS103 Linux驱动源代码
  4. PYTHON对接验证码通知短信API
  5. 所向无前 正当年!掌上英雄联盟S10换肤设计小结
  6. Facebook vs推特: 谁才是社交媒体王者?
  7. 正则表达式实现电话,固话,email查询
  8. 物联网网关BL110对接华为云
  9. 英特尔530和535哪个好_游戏在哪个硬盘安家更好?HDD+SSD搭档依旧合理
  10. mysql修改添加数字_mysql数据库插入将所有ID更改为4294967295