TensorFlow指定GPU/CPU进行训练和输出devices信息
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_lib
print(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 FMA
2019-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 zero
2019-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.1
2019-05-23 20:12:47.529891: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1992000000 Hz
2019-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): <undefined>, <undefined>
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.341
pciBusID: 0000:01:00.0
totalMemory: 1.96GiB freeMemory: 1.92GiB
2019-05-23 20:12:47.530468: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-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: 268435456
locality {
}
incarnation: 1736381910647465363
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 10300285037066135290
physical_device_desc: "device: XLA_GPU device"
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 6680013036417599682
physical_device_desc: "device: XLA_CPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 1823080448
locality {
bus_id: 1
links {
}
}
incarnation: 7894169161128462449
physical_device_desc: "device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1"
]
找到对应devices的name,复制双引号下的名字,替换第1的代码中的单引号的内容,就可以指定对应的设备进行训练了。
TensorFlow指定GPU/CPU进行训练和输出devices信息的更多相关文章
- TensorFlow指定GPU使用及监控GPU占用情况
查看机器上GPU情况 命令: nvidia-smi 功能:显示机器上gpu的情况 命令: nvidia-smi -l 功能:定时更新显示机器上gpu的情况 命令:watch -n 3 nvidia-s ...
- Keras/Tensorflow选择GPU/CPU运行
首先,导入os,再按照PCI_BUS_ID顺序,从0开始排列GPU, import os os.environ["CUDA_DEVICE_ORDER"] = "PCI_B ...
- 指定Gpu range系列函数
tensorflow指定GPU训练 import os os.environ[CUDA_VISIABLE_DEVICES] = '0,1'记住DEVICES是复数 range()返回的是range o ...
- [转] pytorch指定GPU
查过好几次这个命令,总是忘,转一篇mark一下吧 转自:http://www.cnblogs.com/darkknightzh/p/6836568.html PyTorch默认使用从0开始的GPU,如 ...
- TensorFlow指定CPU和GPU方法
TensorFlow指定CPU和GPU方法 TensorFlow 支持 CPU 和 GPU.它也支持分布式计算.可以在一个或多个计算机系统的多个设备上使用 TensorFlow. TensorFlow ...
- TensorFlow——tensorflow指定CPU与GPU运算
1.指定GPU运算 如果安装的是GPU版本,在运行的过程中TensorFlow能够自动检测.如果检测到GPU,TensorFlow会尽可能的利用找到的第一个GPU来执行操作. 如果机器上有超过一个可用 ...
- 安装 tensorflow 1.1.0;以及安装其他相似版本tensorflow遇到的问题;tensorflow 1.13.2 cuda-10环境变量配置问题;Tensorflow 指定训练时如何指定使用的GPU;
# 安装 2.7 环境conda create -n python2. python= conda activate python2. # 安装 1.1.0 gpu版本pip # 配置环境变量expo ...
- Tensorflow检验GPU是否安装成功 及 使用GPU训练注意事项
1. 已经安装cuda但是tensorflow仍然使用cpu加速的问题 电脑上同时安装了GPU和CPU版本的TensorFlow,本来想用下面代码测试一下GPU程序,但无奈老是没有调用GPU. imp ...
- tensorflow 指定使用gpu处理,tensorflow占用多个GPU但只有一个在跑
我们在刚使用tensorflow的过程中,会遇到这个问题,通常我们有多个gpu,但是 在通过nvidia-smi查看的时候,一般多个gpu的资源都被占满,但是只有一个gpu的GPU-Util 和 21 ...
随机推荐
- 日记 进程 ip /端口
查看日记: tail -f log.txt 循环查看 cat info 查看文件 less info 查看文件 head -n 10 /vv/v ...
- Python学习笔记——天气查询代码
天气查询代码1 # 此程序无法运行,因为中国天气网的api接口被关闭了 import urllib.request import json import pickle #建立城市字典 pickle_f ...
- [Cometoj#3 D]可爱的菜菜子_线段树_差分_线性基
可爱的菜菜子 题目链接:https://cometoj.com/contest/38/problem/D?problem_id=1543 数据范围:略. 题解: 首先,如果第一个操作是单点修改,我们就 ...
- 【Python】【demo实验36】【基础实验】【求3*3矩阵的主对角线之和】
题目: 求一个3*3矩阵主对角线元素之和. 主对角线:从左上多右下的书归为主对角线 副对角线:从左下至右上的数归为副对角线. 我的源码: #!/usr/bin/python # encoding=ut ...
- 【AtCoder】ARC065
ARC065 C - 白昼夢 / Daydream 直接递推就好 #include <bits/stdc++.h> #define fi first #define se second # ...
- Java web server 基本实现原理
public class WebServer { //服务端Socket只要一个,所以定义成static, 同一时间只能一个线程访问(主线程) private static ServerSocket ...
- JS数据拷贝
JS的拷贝可分为浅拷贝和深拷贝: 浅拷贝:如果数组元素是基本类型,就会拷贝一份,互不影响,而如果是对象或者数组,就会只拷贝对象和数组的引用,这样我们无论在新旧数组进行了修改,两者都会发生变化. 深拷贝 ...
- centos8自定义目录安装nginx
1.安装工具和库 # PCRE是一个Perl库,包括 perl 兼容的正则表达式库.nginx 的 http 模块使用 pcre 来解析正则表达式 # zlib库提供了很多种压缩和解压缩的方式, ng ...
- Python基础总结之第六天开始【先简单认识一次函数】(新手可相互督促)
午休后,看看电视,在回顾下新的知识----函数.相信很多小伙伴在学习python后 ,学到函数就会有一部分人放弃了,从努力到放弃(内容过于真实) 好希望我也能有很多粉丝,hhh.... 函数: 什么是 ...
- Asp.net core 学习笔记 ef core Surrogate Key, Natural Key, Alternate Keys
更新: 2019-12-23 foreignkey 并不一样要配上 alternate key,其实只要是 unique 就可以了. 和 sql server 是一样的, 经常有一种错觉 primar ...