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. jquery----Ajax补充

    jquery实现ajax请求 <script> //$.ajax的两种使用方式: //$.ajax(settings); //$.ajax(url,[settings]); $(" ...

  2. 实现本地svn目录同步时,服务器的相应目录保持自动同步

    提交一个TEST文件夹 但是服务器上并没有显示 而新检出的目录却有 这个时候需要手动去update才会显示,而不可能每次都去update,所以,就用到配置自动更新 1.创建svn目录:mkdir /v ...

  3. AI-CBV写法

    AI-CBV写法 CBV固定样式 #url.py from django.conf.urls import url from django.contrib import admin from app0 ...

  4. plsql的汉化问题

    1:汉化工具下载地址:https://www.allroundautomations.com/bodyplsqldevreg.html 汉化吗.然后选择chinese就行了: 2:对安装(解压缩好的哦 ...

  5. [转] js中的钩子机制(hook)

    什么是钩子机制?使用钩子机制有什么好处? 钩子机制也叫hook机制,或者你可以把它理解成一种匹配机制,就是我们在代码中设置一些钩子,然后程序执行时自动去匹配这些钩子:这样做的好处就是提高了程序的执行效 ...

  6. vue中methods一个方法调用另外一个方法

    转自http://blog.csdn.net/zhangjing1019/article/details/77942923 vue在同一个组件内: methods中的一个方法调用methods中的另外 ...

  7. Python_python内置加密模块

    数据加密: 对称加密:数据加密和解密使用相同的密钥,主要解决数据的机密性(DES,AES) 非对称加密(公匙加密):数据加密和解密使用的不同密钥,主要用于身份的验证(DSA,RSA) 单向加密:只能加 ...

  8. 远程连接mongodb服务器

  9. spark操作kudu之DML操作

    Kudu支持许多DML类型的操作,其中一些操作包含在Spark on Kudu集成 包括: INSERT - 将DataFrame的行插入Kudu表.请注意,虽然API完全支持INSERT,但不鼓励在 ...

  10. 关于mac远程链接window服务器以及实现共享文件

    要最近换了新电脑mac 虽然运行速度666  但是真的很多地方都使用不习惯 这里记录一下 关于 远程链接window主机的问题 方便以后用 首先是 链接: 在应用里 找到    然后类似于  wind ...