tensorflow急切执行概述

Eager execution is an imperative, define-by-run interface where operations are executed immediately as they are called from Python. This makes it easier to get started with TensorFlow, and can make research and development more intuitive. A vast majority of the TensorFlow API remains the same whether eager execution is enabled or not. As a result, the exact same code that constructs TensorFlow graphs (e.g. using the layers API) can be executed imperatively by using eager execution. Conversely, most models written with Eager enabled can be converted to a graph that can be further optimized and/or extracted for deployment in production without changing code.
**急切执行**是一个必要的,逐个运行的界面,其中操作在从Python调用时立即执行。 这使得TensorFlow开始变得更容易,并且可以使研究和开发更加直观。 无论是否启用了急切执行,绝大多数TensorFlow API都保持不变。 通过使用急切执行,可以强制执行构造TensorFlow图的完全相同的代码。 相反,大多数使用Eager编写的模型都可以转换为可以进一步优化和/或提取的图形,以便在不更改代码的情况下在生产中进行部署。

代码图解分析如下

代码

from __future__ import absolute_import, division, print_function

import numpy as np
import tensorflow as tf
import tensorflow.contrib.eager as tfe # Set Eager API
print("Setting Eager mode...")
tfe.enable_eager_execution() # Define constant tensors
print("Define constant tensors")
a = tf.constant(2)
print("a = %i" % a)
b = tf.constant(3)
print("b = %i" % b) # Run the operation without the need for tf.Session
print("Running operations, without tf.Session")
c = a + b
print("a + b = %i" % c)
d = a * b
print("a * b = %i" % d) # Full compatibility with Numpy
print("Mixing operations with Tensors and Numpy Arrays") # Define constant tensors
a = tf.constant([[2., 1.],
[1., 0.]], dtype=tf.float32)
print("Tensor:\n a = %s" % a)
b = np.array([[3., 0.],
[5., 1.]], dtype=np.float32)
print("NumpyArray:\n b = %s" % b) # Run the operation without the need for tf.Session
print("Running operations, without tf.Session") c = a + b
print("a + b = %s" % c) d = tf.matmul(a, b)
print("a * b = %s" % d) print("Iterate through Tensor 'a':")
for i in range(a.shape[0]):
for j in range(a.shape[1]):
print(a[i][j])

参考点

https://github.com/brightyu/TensorFlow-Examples/blob/master/examples/

机器学习系列-tensorflow-01-急切执行API的更多相关文章

  1. Weka中数据挖掘与机器学习系列之Weka系统安装(四)

    能来看我这篇博客的朋友,想必大家都知道,Weka采用Java编写的,因此,具有Java“一次编译,到处运行”的特性.支持的操作系统有Windows x86.Windows x64.Mac OS X.L ...

  2. tensorflow中slim模块api介绍

    tensorflow中slim模块api介绍 翻译 2017年08月29日 20:13:35   http://blog.csdn.net/guvcolie/article/details/77686 ...

  3. Spark2.0机器学习系列之9: 聚类(k-means,Bisecting k-means,Streaming k-means)

    在Spark2.0版本中(不是基于RDD API的MLlib),共有四种聚类方法:      (1)K-means      (2)Latent Dirichlet allocation (LDA)  ...

  4. 机器学习之TensorFlow编程环境_TensorFlow_Estimator

    title: Machine-learning subtitle: 1. 机器学习之TensorFlow编程环境_TensorFlow_Estimator date: 2018-12-13 10:17 ...

  5. Weka中数据挖掘与机器学习系列之Exploer界面(七)

    不多说,直接上干货! Weka的Explorer(探索者)界面,是Weka的主要图形化用户界面,其全部功能都可通过菜单选择或表单填写进行访问.本博客将详细介绍Weka探索者界面的图形化用户界面.预处理 ...

  6. Hadoop 系列(三)Java API

    Hadoop 系列(三)Java API <dependency> <groupId>org.apache.hadoop</groupId> <artifac ...

  7. JavaScript进阶系列05,事件的执行时机, 使用addEventListener为元素同时注册多个事件,事件参数

    本篇体验JavaScript事件的基本面,包括: ■ 事件必须在页面元素加载之后起效■ 点击事件的一个简单例子■ 为元素注册多个点击事件■ 获取事件参数 ■ 跨浏览器事件处理 □ 事件必须在页面元素加 ...

  8. Zookeeper 系列(五)Curator API

    Zookeeper 系列(五)Curator API 一.Curator 使用 Curator 框架中使用链式编程风格,易读性更强,使用工程方法创建连接对象使用. (1) CuratorFramewo ...

  9. Zookeeper 系列(三)Zookeeper API

    Zookeeper 系列(三)Zookeeper API 本节首先介绍 Zookeeper 的 Shell 命令,再对 Java 操作 Zookeeper 的三种方式进行讲解,本节先介绍 Zookee ...

随机推荐

  1. 性能测试四十二:sql案例之联合索引最左前缀

    联合索引:一个索引同时作用于多个字段 联合索引的最左前缀: A.B.C3个字段--联合索引 这个时候,可以使用的查询条件有:A.A+B.A+C.A+B+C,唯独不能使用B+C,即最左侧那个字段必须匹配 ...

  2. 配置web pack loader 报错:Module build failed: Error: The node API for `babel` has been moved to `babel-core`.

    报错如下 Module build failed: Error: The node API for `babel` has been moved to `babel-core`. 在我配置loader ...

  3. 访问和获取Cookie

    Cookie[] cookies = request.getCookies();//从会话里取出Cookie并放在Cookie数组里 if(cookies!=null) { for(Cookie c: ...

  4. 20165206第4次实验《Android程序设计》实验报告

    20165206第4次实验<Android程序设计>实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:韩啸 学号:20165206 指导教师:娄嘉鹏 实验日期:2 ...

  5. 小甲鱼python基础教程飞机大战源码及素材

    百度了半天小甲鱼python飞机大战的源码和素材,搜出一堆不知道是什么玩意儿的玩意儿. 最终还是自己对着视频一行行代码敲出来. 需要的同学点下面的链接自取. 下载

  6. JDK1.7 Update14 HotSpot虚拟机GC收集器

    在测试服务器上使用如下命令可以查看当前使用的 GC收集器,当然不止这一个命令可以看到,还有其他一些方式 第三列”=”表示第四列是参数的默认值,而”:=” 表明了参数被用户或者JVM赋值了 [csii@ ...

  7. ASP.NET CORE 配置管理

    配置管理简单例子(添加内存配置) using Microsoft.Extensions.Configuration; using System; using System.Collections.Ge ...

  8. Sqlserver2014 Master....提示异常,IIS未安装

    Q:使用Windos认证,登录失败,问题待解决补充 Q:打开Sqlserver2014  Master....提示异常,IIS未安装 解决方案: 安装iis配置,并全部勾选asp.net特性等 Tip ...

  9. IO流-file

    1.1 IO概述 回想之前写过的程序,数据都是在内存中,一旦程序运行结束,这些数据都没有了,等下次再想使用这些数据,可是已经没有了.那怎么办呢?能不能把运算完的数据都保存下来,下次程序启动的时候,再把 ...

  10. 2018项目UML设计-课堂实战

    1. 团队信息 队名:小白吃队 成员: 卢泽明 031602328 蔡文斌 031602301 葛亮 031602617 刘浩 031602423 张扬 031602345 李泓 031602321 ...