機器學習系列-tensorflow-01-急切執行API

来源:https://www.cnblogs.com/brightyuxl/archive/2018/10/30/9880172.html
-Advertisement-
Play Games

tensorflow急切執行概述 Eager execution is an imperative, define by run interface where operations are executed immediately as they are called from Python. T ...


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/


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 利用tensorflow實現數據的線性回歸 導入相關庫 import tensorflow as tf import numpy import matplotlib.pyplot as plt rng = numpy.random 參數設置 learning_rate = 0.01 training ...
  • tensorflow常數操作 結果 a=2, b=3 Addition with constants: 5 Multiplication with constants: 6 tensorflow變數操作 變數作為圖形輸入,構造器的返回值作為變數的輸出,在運行會話時,傳入變數的值,在進行運算。 結果 ...
  • 線程的狀態 線程的所有狀態在Thread中的State枚舉中定義 public enum State{ NEW, //剛剛新建的線程,還沒有開始執行 RUNNABLE, //執行時的狀態 BLOCKED, //在執行過程中遇到synchronized同步塊,進入blocked阻塞狀態,暫停執行,直到 ...
  • 前通過傳智的視頻自學了webservice的基本使用,也瞭解到webservice就是一種跨編程語言和跨操作系統平臺的遠程調用技術。 對於這些理論知識在這裡也不再做過多的解釋,本次主要就是記錄與分享使用cxf 框架完成遠程調用氣象局提供的介面,來實現天氣查詢的全過程。 1、項目搭建 * 創建一個ma ...
  • 服務發佈者 在服務發佈者的springboot主配置文件application.properties中添加dubbo配置 服務調用者 在服務調用者的springboot主配置文件application.properties中添加dubbo配置 應用配置參數(必須配置) 服務掃描的包 註冊中心支持的配 ...
  • 多線程 mutex的理解 mutex,我的理解是每個mutex對象都是一個帶鎖頭的門,這個門有兩個狀態,門開著和門關著,感覺像是廢話。。。 當想查看門的里東西,或者把東西放進門裡,或者從門裡拿出東西前,都需要看看,門是否是打開的。 如果門是打開的,就要進去後趕緊把門關上。關上後,就可以查看屋子裡的東 ...
  • 運算符與分支結構 運算符 賦值運算符 用'='表示,左邊只能是變數 算術運算符 +、-、*:加、減、乘 /:除法運算,結果是浮點型 //:除法運算,結果是整型 %:求餘 **:求冪 複合運算符 +=、-=、*=、/=、//=、%=、**= 示例:a = a+b 等價於 a += b 關係運算符 >、 ...
  • # 動態傳參:# * 表示接收所有 位置參數 的動態傳參# 傳參時自動把實參打包成 元祖 給形參 1 def chi(*food): 2 print(food) 3 return food 4 5 chi() # 動態傳參可以為空不傳參 6 # chi("紫菜湯",food="雞蛋湯") # * a... ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...