博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TensorFlow指定GPU/CPU进行训练和输出devices信息
阅读量:6758 次
发布时间:2019-06-26

本文共 3129 字,大约阅读时间需要 10 分钟。

TensorFlow指定GPU/CPU进行训练和输出devices信息

1.在tensorflow代码中指定GPU/CPU进行训练

with tf.device('/gpu:0'):    ....with tf.device('/gpu:1'):    ...with tf.device('/cpu:0'):    ...

2.输出devices的信息

在指定devices的时候往往不知道具体的设备信息,这时可用下面的代码查看对应的信息

进入Python环境

from tensorflow.python.client import device_libprint(device_lib.list_local_devices())

输出以下信息:

2019-05-23 20:12:47.415412: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA2019-05-23 20:12:47.509275: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:998] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero2019-05-23 20:12:47.509632: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x14b6e60 executing computations on platform CUDA. Devices:2019-05-23 20:12:47.509660: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): GeForce MX150, Compute Capability 6.12019-05-23 20:12:47.529891: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1992000000 Hz2019-05-23 20:12:47.530293: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x1b7b140 executing computations on platform Host. Devices:2019-05-23 20:12:47.530318: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): 
,
2019-05-23 20:12:47.530451: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties: name: GeForce MX150 major: 6 minor: 1 memoryClockRate(GHz): 1.341pciBusID: 0000:01:00.0totalMemory: 1.96GiB freeMemory: 1.92GiB2019-05-23 20:12:47.530468: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 02019-05-23 20:12:47.531469: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:2019-05-23 20:12:47.531487: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0 2019-05-23 20:12:47.531494: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N 2019-05-23 20:12:47.531563: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 1738 MB memory) -> physical GPU (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)[name: "/device:CPU:0"device_type: "CPU"memory_limit: 268435456locality {}incarnation: 1736381910647465363, name: "/device:XLA_GPU:0"device_type: "XLA_GPU"memory_limit: 17179869184locality {}incarnation: 10300285037066135290physical_device_desc: "device: XLA_GPU device", name: "/device:XLA_CPU:0"device_type: "XLA_CPU"memory_limit: 17179869184locality {}incarnation: 6680013036417599682physical_device_desc: "device: XLA_CPU device", name: "/device:GPU:0"device_type: "GPU"memory_limit: 1823080448locality { bus_id: 1 links { }}incarnation: 7894169161128462449physical_device_desc: "device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1"]

找到对应devices的name,复制双引号下的名字,替换第1的代码中的单引号的内容,就可以指定对应的设备进行训练了。

转载于:https://www.cnblogs.com/youpeng/p/10914237.html

你可能感兴趣的文章
(转)过滤器原理
查看>>
JavaScript 触发click事件 兼容FireFox,IE 和 Chrome
查看>>
【英语称谓】软件行业外企称谓简称
查看>>
实现打印级别且带图片的Excel 方案
查看>>
使用 Java 程序写文件时,记得要 flush()
查看>>
OpenCV在矩阵上的卷积
查看>>
linux 编译java并打包
查看>>
What is Entity Framework?
查看>>
SQL Server 2008性能故障排查(一)——概论
查看>>
NGUI ScrollView动态加入和删除对象。
查看>>
****RESTful API 设计最佳实践(APP后端API设计参考典范)
查看>>
Linux内存管理-高端内存(二)
查看>>
[LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串
查看>>
FU-A分包方式,以及从RTP包里面得到H.264数据和AAC数据的方法。。
查看>>
[LeetCode] 4Sum 四数之和
查看>>
Hello World 之 控制台版本(Console Application)
查看>>
IOS 播放动态Gif图片
查看>>
随笔1
查看>>
HTML中Select的使用具体解释
查看>>
Java synchronized
查看>>