TensorFlow GPU 的使用
一、TensorFlow 设备分配
1、设备分配规则
If a TensorFlow operation has both CPU and GPU implementations, the GPU devices will be given priority when the operation is assigned to a device.
2、手动指定设备分配
- 如果你不想让系统自动为 operation 分配设备, 而是自己手动指定, 可以用
with tf.device
创建一个设备环境, 这个环境下的 operation 都统一运行在指定的设备上. - 代码示例如下:
1 # op 在 cpu 上运算
2 with tf.device('/cpu:0'):
3 a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
4 b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
5
6 # op 在 gpu 上运算
7 with tf.device('/device:GPU:2'):
8 a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
9 b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
10
11 # op 在 gpus 上运算
12 for d in ['/device:GPU:2', '/device:GPU:3']:
13 with tf.device(d):
14 a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3])
15 b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2])
二、TensorFlow GPU 配置
1、指定可以被看见的GPU设备
1 import os
2
3 # 默认情况,TF 会占用所有 GPU 的所有内存, 我们可以指定
4 # 只有 GPU0 和 GPU1 这两块卡被看到,从而达到限制其使用所有GPU的目的
5 os.environ['CUDA_VISIBLE_DEVICES'] = '0, 1'
6
7 # 打印 TF 可用的 GPU
8 print os.environ['CUDA_VISIBLE_DEVICES']
9 >>> 0, 1
2、限定使用显存的比例
1 # 在开启对话session前,先创建一个 tf.ConfigProto() 实例对象
2 # 通过 allow_soft_placement 参数自动将无法放在 GPU 上的操作放回 CPU
3 gpuConfig = tf.ConfigProto(allow_soft_placement=True)
4
5 # 限制一个进程使用 60% 的显存
6 gpuConfig.gpu_options.per_process_gpu_memory_fraction = 0.6
7
8 # 把你的配置部署到session
9 with tf.Session(config=gpuConfig) as sess:
10 pass
11
12 这样,如果你指定的卡的显存是8000M的话,你这个进程只能用4800M。
3、需要多少拿多少
1 # 在开启对话session前,先创建一个 tf.ConfigProto() 实例对象
2 # 通过 allow_soft_placement 参数自动将无法放在 GPU 上的操作放回 CPU
3 gpuConfig = tf.ConfigProto(allow_soft_placement=True)
4
5 # 运行时需要多少再给多少
6 gpuConfig.gpu_options.allow_growth = True
7
8 # 把你的配置部署到session
9 with tf.Session(config=gpuConfig) as sess:
10 pass
4、GPU 使用总结
1 import os
2 os.environ['CUDA_VISIBLE_DEVICES'] = '0, 1'
3
4 gpuConfig = tf.ConfigProto(allow_soft_placement=True)
5 gpuConfig.gpu_options.allow_growth = True
6
7 with tf.Session(config=gpuConfig) as sess:
8 pass
TensorFlow GPU 的使用的更多相关文章
- 【转】Ubuntu 16.04安装配置TensorFlow GPU版本
之前摸爬滚打总是各种坑,今天参考这篇文章终于解决了,甚是鸡冻\(≧▽≦)/,电脑不知道怎么的,安装不了16.04,就安装15.10再升级到16.04 requirements: Ubuntu 16.0 ...
- Ubuntu 16.04 + CUDA 8.0 + cuDNN v5.1 + TensorFlow(GPU support)安装配置详解
随着图像识别和深度学习领域的迅猛发展,GPU时代即将来临.由于GPU处理深度学习算法的高效性,使得配置一台搭载有GPU的服务器变得尤为必要. 本文主要介绍在Ubuntu 16.04环境下如何配置Ten ...
- 备注: ubt 16.04 安装 gtx 1060 --- 成功运行 tensorflow - gpu
---------------------------------------------------------------------------------------------------- ...
- 通过Anaconda在Ubuntu16.04上安装 TensorFlow(GPU版本)
一. 安装环境 Ubuntu16.04.3 LST GPU: GeForce GTX1070 Python: 3.5 CUDA Toolkit 8.0 GA1 (Sept 2016) cuDNN v6 ...
- Win10上安装Keras 和 TensorFlow(GPU版本)
一. 安装环境 Windows 10 64bit 家庭版 GPU: GeForce GTX1070 Python: 3.5 CUDA: CUDA Toolkit 8.0 GA1 (Sept 2016 ...
- Win10 x64 + CUDA 10.0 + cuDNN v7.5 + TensorFlow GPU 1.13 安装指南
Win10 x64 + CUDA 10.0 + cuDNN v7.5 + TensorFlow GPU 1.13 安装指南 Update : 2019.03.08 0. 环境说明 硬件:Ryzen R ...
- windows安装tensorflow GPU
一.安装Anaconda Anaconda是Python发行包,包含了很多Python科学计算库.它是比直接安装Python更好的选择. 二.安装Tensorflow 如果安装了tensorflow, ...
- TensorFlow DeepLab教程初稿-tensorflow gpu安装教程
TensorFlow DeepLab教程初稿-tensorflow gpu安装教程 商务合作,科技咨询,版权转让:向日葵,135-4855__4328,xiexiaokui#qq.com Summar ...
- 记录从裸机到TensorFlow GPU版运行 的配置过程
实验室原来有一台装Ubuntu Server系统的服务器,安装有tensorflow,在使用过程中经常出现断网.死机.自动关机等毛病,忍无可忍,决定重装系统 配置如下:Dell工作站,Xeon-E5 ...
随机推荐
- 洛谷P1186 玛丽卡 spfa+删边
洛谷P1186 玛丽卡http://blog.csdn.net/huihao123456/article/details/73414139题目描述 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. ...
- Red Hat 6.5 本地yum源的配置
在没有网络的情况下,想要使用yum源进行软件的安装就显得非常困难了.所以有时候配置本地的yum源也是非常必要的. 准备工作: rad hat 的ISO镜像文件. 1.创建一个文件夹,用于挂载ISO镜像 ...
- [Schema] I have updated my XML Schema for my service but SoapUI still generates/validates according to the old schema.
SoapUI caches XML schemas when they are first loaded. If you need to force a reload of an interfaces ...
- CENTOS7 YUM安装BOOST1.53(静态版本)
按照之前的博文更新163的源之后,执行: yum install boost-static.i686 yum install boost-devel.i686 yum install boost-do ...
- STL中 map 和 multimap
1. 所在头文件<map>. 命名空间std, 声明如下: namespace std{ template <class Key,class T, class Compare = l ...
- [GO]并的爬取捧腹的段子
package main import ( "fmt" "strconv" "net/http" "regexp" &q ...
- [operator]jenkins+gitlab/Webhook自动构建发布
开发同事在提交代码到gitlab后,需要使用jenkins对代码进行构建,每次都需要手动操作会很繁琐,如果工程很大,那么也会浪费时间,gitlab的webhook功能,可以在代码提交后自动调用jenk ...
- git的使用和一些命令
1. https://github.com/ 在这个网站注册一个帐号. http://gitref.org/zh/creating/ 待会写.. [命令] a)
- C# JSON使用过程中开发的小工具
我在用JSON的过程中,经常要去看一下JSON的结构,而JSON串大不部分时候都是未格式化的数据,一次我不得不用一些网页上的在线解析和格式化工具来进行格式化查看,但是这些网页有时候并不好用:因此就结合 ...
- Android adb 命令
一.概述 作为一名开发者,相信对adb指令一定不会陌生.那么在手机连接adb后,可通过am命令做很多操作: (1) 拨打电话10086 adb shell am start -a android.in ...