chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內(nèi)不再提示

【連載】深度學習筆記7:Tensorflow入門

人工智能實訓營 ? 2018-08-24 18:31 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

從前面的學習筆記中,筆者和大家一起使用了 numpy 一步一步從感知機開始到兩層網(wǎng)絡以及最后實現(xiàn)了深度神經(jīng)網(wǎng)絡算法搭建。而后我們又討論了改善深度神經(jīng)網(wǎng)絡的基本方法,包括神經(jīng)網(wǎng)絡的正則化、參數(shù)優(yōu)化和調(diào)參等問題。這一切工作我們都是基于numpy 完成的,沒有調(diào)用任何深度學習框架。在學習深度學習的時候,一開始不讓大家直接上手框架可謂良苦用心,旨在讓大家能夠跟筆者一樣,一步一步通過 numpy 搭建神經(jīng)網(wǎng)絡的過程就是要讓你能夠更加深入的理解神經(jīng)網(wǎng)絡的架構(gòu)、基本原理和工作機制,而不是黑箱以視之。

但學習到這個階段,你已充分理解了神經(jīng)網(wǎng)絡的工作機制,馬上就要接觸更深層次的卷積神經(jīng)網(wǎng)絡(CNN)和遞歸神經(jīng)網(wǎng)絡(RNN),依靠純手工去搭建這些復雜的神經(jīng)網(wǎng)絡恐怕并不現(xiàn)實。這時候就該深度學習框架出場了。針對深度學習,目前有很多優(yōu)秀的學習框架,比如說筆者馬上要講的 Tensorflow,微軟的 CNTK,伯克利視覺中心開發(fā)的 caffe,以及別具一格的 PyTorch 和友好易用的 keras,本系列深度學習筆記打算從 Tensorflow 開始,對三大主流易用的深度學習框架 TensorflowPyTorchkeras 進行學習和講解。選擇這三個框架的原因在于其簡單易用、方便編程和運行速度相對較快。

作為谷歌的深度學習框架, Tensorflow 在深度學習領域可謂風頭無二。其中 Tensor 可以理解為類似于 numpy 的 N 維數(shù)組,名為張量; flow 則意味著 N 維數(shù)組的流計算,而 Tensor 的數(shù)據(jù)流計算形式則為一個計算圖的形式進行計算。這里重點提一下,如果大學本科期間的線性代數(shù)忘記了的話,我勸你趕緊回去翻一翻,線性代數(shù)和矩陣論是深度學習的基礎,希望你能熟練掌握。


先看個簡單的例子。

importtensorflowastf#Definey_hatconstant.Setto36.y_hat=tf.constant(36,name='y_hat')
#Definey.Setto39y=tf.constant(39,name='y')#Createavariableforthelossloss=tf.Variable((y-y_hat)**2,name='loss')#Wheninitisrunlater(session.run(init)),thelossvariablewillbeinitializedandreadytobecomputedinit=tf.global_variables_initializer()#Createasessionandprinttheoutputwithtf.Session()assession:
#Initializesthevariables
session.run(init)
#Printstheloss
print(session.run(loss))
9

在上述代碼中,我們首先定義了兩個常量,然后定義了一個 loss Tensor(變量),之后對變量進行初始化,創(chuàng)建計算會話,最后執(zhí)行會話計算并打印結(jié)果。所以我們可以看到運行 Tensorflow 的基本機制:
創(chuàng)建一些尚未被執(zhí)行的張量——
定義這些張量之間的運算操作——初始化這些張量——創(chuàng)建會話——執(zhí)行會話

需要注意的一點是,創(chuàng)建會話后一定要執(zhí)行這個會話,且看下面示例:

a=tf.constant(2)
b=tf.constant(10)
c=tf.multiply(a,b)
print(c)
Tensor("Mul:0",shape=(),dtype=int32)

在上面的示例中,我們創(chuàng)建了兩個 TensorTensor 之間的乘積運算,但直接打印的結(jié)果卻不是我們想要看到的 20. 原因則在于這里我們沒有創(chuàng)建會話并執(zhí)行,只是打印了兩個張量運算之后的張量。創(chuàng)建會話并執(zhí)行操作如下:

sess=tf.Session()
print(sess.run(c))
20

除了直接定義變量之外,我們還可以通過創(chuàng)建占位符變量來稍后為之賦值,然后在運行會話中傳入一個 feed_dict ,示例如下:

x=tf.placeholder(tf.int64,name='x')
print(sess.run(2*x,feed_dict={x:3}))
sess.close()
6

相信你已經(jīng)大致明白了基于張量運算的 Tensorflow 的底層運行機制了??偨Y(jié)而言就是:創(chuàng)建張量、初始化張量、創(chuàng)建會話并執(zhí)行。

下面展示幾個 Tensorflow 的神經(jīng)網(wǎng)絡計算的基礎函數(shù)示例。

線性函數(shù)
def linear_function():  
""" Implements a linear function: Initializes W to be a random tensor of shape (4,3) Initializes X to be a random tensor of shape (3,1) Initializes b to be a random tensor of shape (4,1) Returns: result -- runs the session for Y = WX + b """ np.random.seed(1) X = tf.constant(np.random.randn(3,1), name='X') W = tf.constant(np.random.randn(4,3), name='W') b = tf.constant(np.random.randn(4,1), name='b') Y = tf.add(tf.matmul(W, X), b) # Create the session using tf.Session() and run it with sess.run(...) on the variable you want to calculate init = tf.global_variables_initializer() sess = tf.Session() sess.run(init) result = sess.run(Y) # close the session sess.close()
return result
計算sigmoid函數(shù)
def sigmoid(z):  
""" Computes the sigmoid of z Arguments: z -- input value, scalar or vector Returns: results -- the sigmoid of z """ x = tf.placeholder(tf.float32, name='x') sigmoid = tf.sigmoid(x)
with tf.Session() as sess: result = sess.run(sigmoid, feed_dict={x: z})
return result
計算損失函數(shù)

640?wx_fmt=png

def cost(logits, labels):  
""" Computes the cost using the sigmoid cross entropy Arguments: logits -- vector containing z, output of the last linear unit (before the final sigmoid activation) labels -- vector of labels y (1 or 0) Note: What we've been calling "z" and "y" in this class are respectively called "logits" and "labels" in the TensorFlow documentation. So logits will feed into z, and labels into y. Returns: cost -- runs the session of the cost (formula (2)) """ # Create the placeholders for "logits" (z) and "labels" (y) (approx. 2 lines) z = tf.placeholder(tf.float32, name='z') y = tf.placeholder(tf.float32, name='y') # Use the loss function (approx. 1 line) cost = tf.nn.sigmoid_cross_entropy_with_logits(logits=z, labels=y) # Create a session (approx. 1 line). See method 1 above. sess = tf.Session() # Run the session (approx. 1 line). sess.run(cost, feed_dict={z: logits, y: labels}) # Close the session (approx. 1 line). See method 1 above. sess.close()
return cost
one hot 編碼

640?wx_fmt=png

def one_hot_matrix(labels, C):  
""" Creates a matrix where the i-th row corresponds to the ith class number and the jth column corresponds to the jth training example. So if example j had a label i. Then entry (i,j) will be 1. Arguments: labels -- vector containing the labels C -- number of classes, the depth of the one hot dimension Returns: one_hot -- one hot matrix """ # Create a tf.constant equal to C (depth), name it 'C'. (approx. 1 line) C = tf.constant(C) # Use tf.one_hot, be careful with the axis (approx. 1 line) one_hot_matrix = tf.one_hot(labels, C, axis=0) # Create the session (approx. 1 line) sess = tf.Session() one_hot = sess.run(one_hot_matrix) # Close the session (approx. 1 line). See method 1 above. sess.close()
return one_hot
參數(shù)初始化
def ones(shape):  """
  Creates an array of ones of dimension shape
  Arguments:
  shape -- shape of the array you want to create

  Returns: 
  ones -- array containing only ones
  """
  # Create "ones" tensor using tf.ones(...). (approx. 1 line)
  ones = tf.ones(shape)  # Create the session (approx. 1 line)
  sess = tf.Session()  # Run the session to compute 'ones' (approx. 1 line)
  ones = sess.run(ones)  # Close the session (approx. 1 line). See method 1 above.
  sess.close()  
return ones

一頓操作之后,我們已經(jīng)將神經(jīng)網(wǎng)絡的一些基礎運算利用 Tensorflow 定義好了。在下一期筆記中,我們將學習如何使用 Tensorflow 搭建神經(jīng)網(wǎng)絡。

本文由《自興動腦人工智能》項目部 凱文 投稿。


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 人工智能
    +關注

    關注

    1813

    文章

    49772

    瀏覽量

    261733
  • 機器學習
    +關注

    關注

    66

    文章

    8541

    瀏覽量

    136248
  • 深度學習
    +關注

    關注

    73

    文章

    5591

    瀏覽量

    123926
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    如何深度學習機器視覺的應用場景

    深度學習視覺應用場景大全 工業(yè)制造領域 復雜缺陷檢測:處理傳統(tǒng)算法難以描述的非標準化缺陷模式 非標產(chǎn)品分類:對形狀、顏色、紋理多變的產(chǎn)品進行智能分類 外觀質(zhì)量評估:基于學習的外觀質(zhì)量標準判定 精密
    的頭像 發(fā)表于 11-27 10:19 ?63次閱讀

    學習物聯(lián)網(wǎng)怎么入門?

    景等。同時,學習物聯(lián)網(wǎng)的基本技術,如傳感器技術、通信技術、云計算等,也是非常重要的。 其次,選擇適合自己的學習方式也是入門學習物聯(lián)網(wǎng)的重要一步。
    發(fā)表于 10-14 10:34

    如何在機器視覺中部署深度學習神經(jīng)網(wǎng)絡

    圖 1:基于深度學習的目標檢測可定位已訓練的目標類別,并通過矩形框(邊界框)對其進行標識。 在討論人工智能(AI)或深度學習時,經(jīng)常會出現(xiàn)“神經(jīng)網(wǎng)絡”、“黑箱”、“標注”等術語。這些概
    的頭像 發(fā)表于 09-10 17:38 ?714次閱讀
    如何在機器視覺中部署<b class='flag-5'>深度</b><b class='flag-5'>學習</b>神經(jīng)網(wǎng)絡

    深度學習對工業(yè)物聯(lián)網(wǎng)有哪些幫助

    深度學習作為人工智能的核心分支,通過模擬人腦神經(jīng)網(wǎng)絡的層級結(jié)構(gòu),能夠自動從海量工業(yè)數(shù)據(jù)中提取復雜特征,為工業(yè)物聯(lián)網(wǎng)(IIoT)提供了從數(shù)據(jù)感知到智能決策的全鏈路升級能力。以下從技術賦能、場景突破
    的頭像 發(fā)表于 08-20 14:56 ?778次閱讀

    自動駕駛中Transformer大模型會取代深度學習嗎?

    [首發(fā)于智駕最前沿微信公眾號]近年來,隨著ChatGPT、Claude、文心一言等大語言模型在生成文本、對話交互等領域的驚艷表現(xiàn),“Transformer架構(gòu)是否正在取代傳統(tǒng)深度學習”這一話題一直被
    的頭像 發(fā)表于 08-13 09:15 ?3934次閱讀
    自動駕駛中Transformer大模型會取代<b class='flag-5'>深度</b><b class='flag-5'>學習</b>嗎?

    嵌入式AI技術之深度學習:數(shù)據(jù)樣本預處理過程中使用合適的特征變換對深度學習的意義

    ? 作者:蘇勇Andrew 使用神經(jīng)網(wǎng)絡實現(xiàn)機器學習,網(wǎng)絡的每個層都將對輸入的數(shù)據(jù)做一次抽象,多層神經(jīng)網(wǎng)絡構(gòu)成深度學習的框架,可以深度理解數(shù)據(jù)中所要表示的規(guī)律。從原理上看,使用
    的頭像 發(fā)表于 04-02 18:21 ?1295次閱讀

    用樹莓派搞深度學習?TensorFlow啟動!

    介紹本頁面將指導您在搭載64位Bullseye操作系統(tǒng)的RaspberryPi4上安裝TensorFlow。TensorFlow是一個專為深度學習開發(fā)的大型軟件庫,它消耗大量資源。您可
    的頭像 發(fā)表于 03-25 09:33 ?980次閱讀
    用樹莓派搞<b class='flag-5'>深度</b><b class='flag-5'>學習</b>?<b class='flag-5'>TensorFlow</b>啟動!

    IPC2221簡略學習筆記

    關于IPC2221的學習筆記。
    發(fā)表于 03-14 18:07 ?7次下載

    如何排除深度學習工作臺上量化OpenVINO?的特定層?

    無法確定如何排除要在深度學習工作臺上量化OpenVINO?特定層
    發(fā)表于 03-06 07:31

    軍事應用中深度學習的挑戰(zhàn)與機遇

    人工智能尤其是深度學習技術的最新進展,加速了不同應用領域的創(chuàng)新與發(fā)展。深度學習技術的發(fā)展深刻影響了軍事發(fā)展趨勢,導致戰(zhàn)爭形式和模式發(fā)生重大變化。本文將概述
    的頭像 發(fā)表于 02-14 11:15 ?828次閱讀

    模電手賬筆記7

    模電手賬筆記7
    的頭像 發(fā)表于 02-13 16:31 ?544次閱讀
    模電手賬<b class='flag-5'>筆記</b>(<b class='flag-5'>7</b>)

    BP神經(jīng)網(wǎng)絡與深度學習的關系

    BP神經(jīng)網(wǎng)絡與深度學習之間存在著密切的關系,以下是對它們之間關系的介紹: 一、BP神經(jīng)網(wǎng)絡的基本概念 BP神經(jīng)網(wǎng)絡,即反向傳播神經(jīng)網(wǎng)絡(Backpropagation Neural Network
    的頭像 發(fā)表于 02-12 15:15 ?1364次閱讀

    深度學習入門:簡單神經(jīng)網(wǎng)絡的構(gòu)建與實現(xiàn)

    深度學習中,神經(jīng)網(wǎng)絡是核心模型。今天我們用 Python 和 NumPy 構(gòu)建一個簡單的神經(jīng)網(wǎng)絡。 神經(jīng)網(wǎng)絡由多個神經(jīng)元組成,神經(jīng)元之間通過權(quán)重連接。我們構(gòu)建一個包含輸入層、隱藏層和輸出層的簡單
    的頭像 發(fā)表于 01-23 13:52 ?857次閱讀

    ES7P0214應用筆記

    電子發(fā)燒友網(wǎng)站提供《ES7P0214應用筆記.pdf》資料免費下載
    發(fā)表于 01-16 16:06 ?0次下載
    ES<b class='flag-5'>7</b>P0214應用<b class='flag-5'>筆記</b>

    ES7P0213應用筆記

    電子發(fā)燒友網(wǎng)站提供《ES7P0213應用筆記.pdf》資料免費下載
    發(fā)表于 01-16 15:26 ?0次下載
    ES<b class='flag-5'>7</b>P0213應用<b class='flag-5'>筆記</b>