机器学习系列-tensorflow-01-急切执行API
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的更多相关文章
- Weka中数据挖掘与机器学习系列之Weka系统安装(四)
能来看我这篇博客的朋友,想必大家都知道,Weka采用Java编写的,因此,具有Java“一次编译,到处运行”的特性.支持的操作系统有Windows x86.Windows x64.Mac OS X.L ...
- tensorflow中slim模块api介绍
tensorflow中slim模块api介绍 翻译 2017年08月29日 20:13:35 http://blog.csdn.net/guvcolie/article/details/77686 ...
- Spark2.0机器学习系列之9: 聚类(k-means,Bisecting k-means,Streaming k-means)
在Spark2.0版本中(不是基于RDD API的MLlib),共有四种聚类方法: (1)K-means (2)Latent Dirichlet allocation (LDA) ...
- 机器学习之TensorFlow编程环境_TensorFlow_Estimator
title: Machine-learning subtitle: 1. 机器学习之TensorFlow编程环境_TensorFlow_Estimator date: 2018-12-13 10:17 ...
- Weka中数据挖掘与机器学习系列之Exploer界面(七)
不多说,直接上干货! Weka的Explorer(探索者)界面,是Weka的主要图形化用户界面,其全部功能都可通过菜单选择或表单填写进行访问.本博客将详细介绍Weka探索者界面的图形化用户界面.预处理 ...
- Hadoop 系列(三)Java API
Hadoop 系列(三)Java API <dependency> <groupId>org.apache.hadoop</groupId> <artifac ...
- JavaScript进阶系列05,事件的执行时机, 使用addEventListener为元素同时注册多个事件,事件参数
本篇体验JavaScript事件的基本面,包括: ■ 事件必须在页面元素加载之后起效■ 点击事件的一个简单例子■ 为元素注册多个点击事件■ 获取事件参数 ■ 跨浏览器事件处理 □ 事件必须在页面元素加 ...
- Zookeeper 系列(五)Curator API
Zookeeper 系列(五)Curator API 一.Curator 使用 Curator 框架中使用链式编程风格,易读性更强,使用工程方法创建连接对象使用. (1) CuratorFramewo ...
- Zookeeper 系列(三)Zookeeper API
Zookeeper 系列(三)Zookeeper API 本节首先介绍 Zookeeper 的 Shell 命令,再对 Java 操作 Zookeeper 的三种方式进行讲解,本节先介绍 Zookee ...
随机推荐
- jmeter 获取数据库表数据作为参数
jmeter - 获取数据库表数据作为参数 在jmeter中使用数据库表数据首先需要设置数据库连接,然后在创建JDBC取样器 1.创建配置元件 JDBC Connection Configuratio ...
- C和C++ 中的const
C++中的const正常情况下是看成编译期的常量,编译器并不为const分配空间,只是在编译的时候将期值保存在名字表中,并在适当的时候折合在代码中.所以,以下代码: #include <iost ...
- document.getElementsByClassName() 原生方法 通过className 选择DOM节点
<div id="box"> <div class="box">1</div> <div class="bo ...
- 计蒜客 X的平方根(二分法)
设计函数int sqrt(int x),计算 xx 的平方根. 输入格式 输入一个 整数 xx,输出它的平方根.直到碰到文件结束符(EOF)为止. 输出格式 对于每组输入,输出一行一个整数,表示输入整 ...
- 利用SVD-推荐未尝过的菜肴2
推荐未尝过的菜肴-基于SVD的评分估计 实际上数据集要比我们上一篇展示的myMat要稀疏的多. from numpy import linalg as la from numpy import * d ...
- SpringMVC - 1.快速入门
1. HelloWorld 步骤: 加入 jar 包 mons-logging-1.1.3.jar spring-aop-4.0.0.RELEASE.jar spring-beans-4.0.0.RE ...
- INFO JobScheduler: Added jobs for time 1524468752000 ms/INFO MemoryStore: Block input-0-1524469143000 stored as bytes in memory/完全分布式 ./bin/run-example streaming.NetworkWordCount localhost 9999无法正常运行
1.完全分布式 ./bin/run-example streaming.NetworkWordCount localhost 9999无法正常运行: 1 [hadoop@slaver1 spark- ...
- [转] git rm与git rm --cached
当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用 git rm file_path 当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制 ...
- Web前端开发:Sublime Text 常用插件
在安装这些插件之前,确保你已经安装了Package Control. 安装Package Control方法: 通过菜单栏View->Show Console 或者快捷键Ctrl+` 打 ...
- word/excel/cad中插入二维码
1.有需求为在word文档中插入二维码,寻访度娘后,大部分人推荐使用QRmaker制作. 2.找寻QRmaker,网上很多都是1.1版本,后来才知道这个版本有问题(对中文支持不好),偶然得到1.3的版 ...