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_functionimport 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/

转载于:https://www.cnblogs.com/brightyuxl/p/9880172.html

机器学习系列-tensorflow-01-急切执行API相关推荐

  1. 机器学习系列(12)_XGBoost参数调优完全指南(附Python代码)

    机器学习系列(12)_XGBoost参数调优完全指南(附Python代码) 原文链接:http://blog.csdn.net/han_xiaoyang/article/details/5266539 ...

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

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

  3. 机器学习系列(三)——目标函数、损失函数以及代价函数

    机器学习基础(三) 机器学习系列(一)--基础概念及分类 机器学习系列(二)--分类及回归问题 文章目录 机器学习基础(三) 4. 代价函数 4.1 为什么要使用代价函数 4.2 目标函数的作用原理 ...

  4. 用于Java开发机器学习和深度学习的Vector API(翻译)

    本文介绍了用于Java开发机器学习和深度学习的Vector API 英语原文链接 https://software.intel.com/en-us/articles/vector-api-develo ...

  5. python 图表_Python入门学习系列——使用Python调用Web API实现图表统计

    使用Python调用Web API实现图表统计 Web API:Web应用编程接口,用于URL请求特定信息的程序交互,请求的数据大多以非常易于处理的格式返回,比如JSON或CSV等. 本文将使用Pyt ...

  6. 阿里巴巴机器学习系列课程

    亲爱的同学们,福利来临!随着机器学习领域的发展越来越火,阿里云机器学习PAI为广大机器学习爱好的学生提供免费的一站式算法平台,该平台提供上百种算法,并且兼容TensorFlow.Caffe.MXNET ...

  7. TensorFlow 2 Object Detection API 教程: 安装

    TensorFlow 2 Object Detection API 教程: 安装 本教程针对的是TensorFlow 2.4,它是TensorFlow 2.x的最新稳定版本. 这是一个循序渐进的教程/ ...

  8. 机器学习系列(4)_机器学习算法一览,应用建议与解决思路

    作者:寒小阳 时间:2016年1月. 出处:http://blog.csdn.net/han_xiaoyang/article/details/50469334 声明:版权所有,转载请联系作者并注明出 ...

  9. 《刨根问底系列》01:操作系统凭什么可以调度程序?

    <刨根问底系列>01:操作系统凭什么可以调度程序? 一.问题的提出 #include<stdio.h>int main() {while(1){printf("hel ...

最新文章

  1. php unicode转义字符串,PHP字符串中的Unicode字符
  2. 设置路径是服务器上的文件,设置服务器文件路径
  3. 新做了一个项目,一个人做的,关于数据传输的项目(架构说明)
  4. DL之CycleGAN:基于TF利用CycleGAN模型对apple2orange数据集实现图像转换—训练测试过程全记录
  5. nginx 查看 $1,$2,$3
  6. Java黑皮书课后题第5章:5.11(找出能被5或6整除的数,但不能同时整除)编写程序,显示从100到1000之间能被5或6整除但不能同时整除的数,每行显示10个。数字之间用一个空格字符隔开
  7. 110. Balanced Binary Tree
  8. Android之Android Studio 快捷键整理分享
  9. REVERSE-PRACTICE-BUUCTF-22
  10. angular $location服务获取url
  11. 字符串--验证回文串
  12. 数据库学mysql python_mysql学习(4)python操作数据库
  13. 如何完全卸载OneDrive (Windows 10 64bit)
  14. python -m的作用
  15. cad迷你画图2020中文版
  16. DWG格式怎样转换成DXF、DWF格式呢?
  17. IIS无法启动问题的解决
  18. 《老路用得上的商学课》1-15学习笔记
  19. 【高等数学】曲线的切线与法平面和曲面的切平面与法线
  20. 选中文本弹出对话框效果(如百度文库)

热门文章

  1. POJ1789-Truck History
  2. 非正弦信号发生器的组成和分析方法
  3. R拓展包的下载与安装
  4. Namp在内网扫描,帮助解决内部网络问题
  5. 城市轨道交通运营管理属于什么院系_城市轨道交通运营管理是什么
  6. iOS 15之后, 微信支持双开甚至多开了?
  7. canvasToTempFilePath: fail SecurityError: The operations is insecure
  8. 《精通labview教程——由浅入深的范例学习(第二版)》课后题答案
  9. RBM(限制玻尔兹曼机)、DBN(深度信念网络)介绍
  10. 每日计划安排表(2019-10-01 至 yyyy-MM-dd)