機器學習系列-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
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...