TensorFlow Action(开山使用篇)
1、TensorFlow安装:
使用pip install tensorflow安装CPU版;
或使用pip install tensorflow-gpu==1.2.1指定版本安装GPU版。
2、TensorFlow测试样例:
import tensorflow as tf
a = tf.constant([1.0, 2.0], name="a")
b = tf.constant([3.0, 4.0], name="b")
add = a + b
sess = tf.Session()
sess.run(add)
使用python的import操作加载TensorFlow;
使用tf.constant函数定义两个常量tensor,并将两个tensor相加;
使用tf.Session函数生成一个会话(session)并通过这个session来计算结果;
以上若运行无误,则说明TensorFlow安装成功。
3、TensorFlow指定GPU占用 示例:
import os
import tensorflow as tf
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""
config = tf.ConfigProto()
# 设置定量的GPU使用量,占用GPU50%的显存
# config.gpu_options.per_process_gpu_memory_fraction = 0.5
# 设置最小的GPU使用量,自动增长:按需求分配显存
config.gpu_options.allow_growth = True
# 打印详细日志信息
config.log_device_placement = True
a = tf.constant([1.0, 2.0], name="a")
b = tf.constant([3.0, 4.0], name="b")
add = a + b
with tf.Session(config=config) as sess:
sess.run(add)
使用os.environ指定具体的GPU,指定GPU占用可参考TensorFlow指定GPU使用及监控GPU占用情况
使用tf.ConfigProto()函数设置config设定GPU使用量及tf的其他属性参数,并在tf.Session()中指定该config。
TensorFlow Action(开山使用篇)的更多相关文章
- [翻译] TensorFlow 分布式之论文篇 "TensorFlow : Large-Scale Machine Learning on Heterogeneous Distributed Systems"
[翻译] TensorFlow 分布式之论文篇 "TensorFlow : Large-Scale Machine Learning on Heterogeneous Distributed ...
- [翻译] TensorFlow 分布式之论文篇 "Implementation of Control Flow in TensorFlow"
[翻译] TensorFlow 分布式之论文篇 "Implementation of Control Flow in TensorFlow" 目录 [翻译] TensorFlow ...
- salesforce lightning零基础学习(十) Aura Js 浅谈三: $A、Action、Util篇
前两篇分别介绍了Component类以及Event类,此篇将会说一下 $A , Action以及 Util. 一. Action Action类通常用于和apex后台交互,设置参数,调用后台以及对结 ...
- [Android Pro] AndroidStudio IDE界面插件开发(进阶篇之Action机制)
转载请注明出处:[huachao1001的专栏:http://blog.csdn.net/huachao1001/article/details/53883500] 从上一篇<AndroidSt ...
- [源码解析] TensorFlow 分布式 DistributedStrategy 之基础篇
[源码解析] TensorFlow 分布式 DistributedStrategy 之基础篇 目录 [源码解析] TensorFlow 分布式 DistributedStrategy 之基础篇 1. ...
- Struts2第二篇【开发步骤、执行流程、struts.xml讲解、defalut-struts讲解】
前言 我们现在学习的是Struts2,其实Struts1和Struts2在技术上是没有很大的关联的.Struts2其实基于Web Work框架的,只不过它的推广没有Struts1好,因此就拿着Stru ...
- Struts2入门这一篇就够了
前言 这是Strtus的开山篇,主要是引入struts框架...为什么要引入struts,引入struts的好处是什么,以及对Struts2一个简单的入门.... 为什么要引入struts? 既然Se ...
- 双显卡笔记本安装CUDA+theano、tensorflow环境
原文出处:http://www.cnblogs.com/jacklu/p/6377820.html 个人知乎主页欢迎关注:https://www.zhihu.com/people/jack_lu,相信 ...
- 统计学习方法:罗杰斯特回归及Tensorflow入门
作者:桂. 时间:2017-04-21 21:11:23 链接:http://www.cnblogs.com/xingshansi/p/6743780.html 前言 看到最近大家都在用Tensor ...
随机推荐
- ubuntu git 下添加 ssh
1 ssh-keygen 产生公钥和私钥 2 cat ~/.ssh/id_rsa.pub 复制出对应的公钥, 3 拷贝到git上的ssh-key里,注意拷贝时,换行处可能会引起错误,要把换行处的空格 ...
- CSS实现鼠标放图片上显示白色边框+文字描写叙述
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java基础篇6之代理
代理的概念与应用 Class clazzProxy = Proxy.getProxyClass(Collection.class.getClassLoader,Collection.class); c ...
- java 几个线程池的理解
http://www.cnblogs.com/dolphin0520/p/3932921.html 这个文章写的很好
- CF - 420B - Online Meeting(思维)
题意:n 个人參加线上会议.某经理记录了中间一段时间的 m 条上下线记录(1 ≤ n, m ≤ 105).+ 表示上线,- 表示下线. leader是指仅仅要有人在线,他都在线的人.求全部可能的lea ...
- hibernate oneToMany 缓存
@OneToMany(mappedBy="carFieldType", cascade={CascadeType.ALL}, fetch = FetchType.EAGER)@Ca ...
- Locust压力测试Odoo
Table of Contents 编写测试任务集 TaskSet 运行 Locust 分布式 运行 master 运行 slave. Locust 是个伸缩性很好的压力测试框架,OdooLo ...
- HDU5294——Tricks Device(最短路 + 最大流)
第一次做最大流的题目- 这题就是堆模板 #include <iostream> #include <algorithm> #include <cmath> #inc ...
- C# Excel
using System.IO;using System.Text;namespace iLIS.Common{ ///<summary> ///生成Excel文档内容 /// 存入工作流 ...
- 基于Repository模式设计项目架构—你可以参考的项目架构设计
关于Repository模式,直接百度查就可以了,其来源是<企业应用架构模式>.我们新建一个Infrastructure文件夹,这里就是基础设施部分,EF Core的上下文类以及Repos ...