1. 程式人生 > >《神經網路和深度學習》之神經網路基礎(第二週)課後作業——神經網路思維的邏輯迴歸

《神經網路和深度學習》之神經網路基礎(第二週)課後作業——神經網路思維的邏輯迴歸

歡迎來到你的第一個程式設計作業,在這次作業中你將會用邏輯迴歸去識別一個貓。並且在這次作業中你將會用神經網路的思維去一步一步的去解決這個問題和磨練你的深度學習的直覺。

說明:

  • 在你的程式碼中不能使用for或while迴圈,除非說明明確要你這麼做。

你將會學習到:

1.建立一個學習演算法的一般結構,包括

  • 初始化引數
  • 計算代價函式和它的梯度
  • 使用最優化演算法(梯度下降)

2.用正確的順序將上面三個函式集合到一個主函式模型裡。

1 程式包

h5py 是與儲存在一個H5檔案上的資料集互動的公共包。

import numpy as np
import matplotlib.pyplot as
plt import h5py import scipy from PIL import Image from scipy import ndimage from lr_utils import load_dataset %matplotlib inline

2 問題集的概述

問題集合”data.h5”包括

  • 被標記的訓練集m_train
  • 未標記的測試集m_test
  • 每個影象由(num_px, num_px, 3)構成,對應於(height ,width,channels)
# Loading the data (cat/non-cat)
train_set_x_orig, train_set
_y, test_set_x_orig, test_set_y, classes = load_dataset()

我們在影象集前加了 “_orig” 表示預處理前。
我們也可以通過索引顯示出來。

# Example of a picture
index = 25
plt.imshow(train_set_x_orig[index])
print ("y = " + str(train_set_y[:, index]) + ", it's a '" + classes[np.squeeze(train_set_y[:, index])].decode("utf-8") +  "' picture."
)

問題:找出下面的值

  • m_train(訓練樣例的個數)
  • m_test(測試樣例的個數)
  • num_px (= height = width 的訓練圖片)
### START CODE HERE ### (≈ 3 lines of code)
m_train = train_set_x_orig.shape[0]
m_test = test_set_x_orig.shape[0]
num_px = train_set_x_orig.shape[1]
### END CODE HERE ###

print ("Number of training examples: m_train = " + str(m_train))
print ("Number of testing examples: m_test = " + str(m_test))
print ("Height/Width of each image: num_px = " + str(num_px))
print ("Each image is of size: (" + str(num_px) + ", " + str(num_px) + ", 3)")
print ("train_set_x shape: " + str(train_set_x_orig.shape))
print ("train_set_y shape: " + str(train_set_y.shape))
print ("test_set_x shape: " + str(test_set_x_orig.shape))
print ("test_set_y shape: " + str(test_set_y.shape))

輸出:Number of training examples: m_train = 209
Number of testing examples: m_test = 50
Height/Width of each image: num_px = 64
Each image is of size: (64, 64, 3)
train_set_x shape: (209L, 64L, 64L, 3L)
train_set_y shape: (1L, 209L)
test_set_x shape: (50L, 64L, 64L, 3L)
test_set_y shape: (1L, 50L)

問題: 重構訓練集和測試集使得一個矩陣影象扁平成一個向量。

X_flatten = X.reshape(X.shape[0], -1).T # X.T is the transpose of X

# Reshape the training and test examples

### START CODE HERE ### (≈ 2 lines of code)
train_set_x_flatten = train_set_x_orig.reshape(train_set_x_orig.shape[0], -1).T
test_set_x_flatten = test_set_x_orig.reshape(test_set_x_orig.shape[0], -1).T
### END CODE HERE ###

print ("train_set_x_flatten shape: " + str(train_set_x_flatten.shape))
print ("train_set_y shape: " + str(train_set_y.shape))
print ("test_set_x_flatten shape: " + str(test_set_x_flatten.shape))
print ("test_set_y shape: " + str(test_set_y.shape))
print ("sanity check after reshaping: " + str(train_set_x_flatten[0:5,0]))

輸出:train_set_x_flatten shape: (12288L, 209L)
train_set_y shape: (1L, 209L)
test_set_x_flatten shape: (12288L, 50L)
test_set_y shape: (1L, 50L)
sanity check after reshaping: [17 31 56 22 33]

歸一化資料集

train_set_x = train_set_x_flatten/255.
test_set_x = test_set_x_flatten/255.

這部分內容需要你記住的是
預處理一個數據集的一般步驟是

  • 找出資料集的維度和形狀(m_train, m_test, num_px, …)
  • 重構資料集為一個向量 (num_px * num_px * 3, 1)
  • 歸一化資料

3 學習演算法的一般架構

以下過程解釋了為什麼邏輯迴歸是一個非常簡單的神經網路
這裡寫圖片描述

演算法的數學表示式

這裡寫圖片描述

通過對所有樣例之和,求代價函式

這裡寫圖片描述

關鍵步驟

  • 初始化模型引數
  • 通過最小化代價函式,學習模型引數
  • 通過學習到的模型在測試集做預測
  • 分析結果和總結

4 構建演算法的各個部分

建立神經網路的主要步驟:

  1. 定義模型結構(例如輸入特徵的數量)
  2. 初始化模型引數
  3. 迴圈部分
    計算當前的損失函式(向前傳播);
    計算損失函式的梯度(反向傳播);
    更新引數(梯度下降)。

通常構建1—3個函式,並把它們集合到一個主函式main()中。

4.1 輔助函式

為了做預測,利用上次作業的sigmoid(),函式計算
這裡寫圖片描述

# GRADED FUNCTION: sigmoid

def sigmoid(z):
    """
    Compute the sigmoid of z

    Arguments:
    z -- A scalar or numpy array of any size.

    Return:
    s -- sigmoid(z)
    """

    ### START CODE HERE ### (≈ 1 line of code)
    s = N1 / (1 + np.exp(-z))
    ### END CODE HERE ###

    return s

print ("sigmoid([0, 2]) = " + str(sigmoid(np.array([0,2]))))

輸出:sigmoid([0, 2]) = [ 0.5 0.88079708]

4.2 初始化引數

將w初始化為與x同維度的零向量

# GRADED FUNCTION: initialize_with_zeros

def initialize_with_zeros(dim):
    """
    This function creates a vector of zeros of shape (dim, 1) for w and initializes b to 0.

    Argument:
    dim -- size of the w vector we want (or number of parameters in this case)

    Returns:
    w -- initialized vector of shape (dim, 1)
    b -- initialized scalar (corresponds to the bias)
    """

    ### START CODE HERE ### (≈ 1 line of code)
    w = np.zeros((dim, 1))
    b = 0
    ### END CODE HERE ###

    assert(w.shape == (dim, 1))
    assert(isinstance(b, float) or isinstance(b, int))

    return w, b

dim = 2
w, b = initialize_with_zeros(dim)
print ("w = " + str(w))
print ("b = " + str(b))

輸出:w = [[ 0.]
[ 0.]]
b = 0

如果輸入為圖片,w將會是(num_px ×× num_px ×× 3, 1)。

4.3 向前傳播和向後傳播

實現propagate(),計算代價函式和他的梯度。

這裡寫圖片描述

# GRADED FUNCTION: propagate

def propagate(w, b, X, Y):
    """
    Implement the cost function and its gradient for the propagation explained above

    Arguments:
    w -- weights, a numpy array of size (num_px * num_px * 3, 1)
    b -- bias, a scalar
    X -- data of size (num_px * num_px * 3, number of examples)
    Y -- true "label" vector (containing 0 if non-cat, 1 if cat) of size (1, number of examples)

    Return:
    cost -- negative log-likelihood cost for logistic regression
    dw -- gradient of the loss with respect to w, thus same shape as w
    db -- gradient of the loss with respect to b, thus same shape as b

    Tips:
    - Write your code step by step for the propagation. np.log(), np.dot()
    """

    m = X.shape[1]

    # FORWARD PROPAGATION (FROM X TO COST)
    ### START CODE HERE ### (≈ 2 lines of code)
    A = sigmoid(np.dot(w.T, X) + b)            # compute activation
    cost = -1 / m * np.sum(Y * np.log(A) + (1 - Y) * np.log(1 - A))          # compute cost
    ### END CODE HERE ###

    # BACKWARD PROPAGATION (TO FIND GRAD)
    ### START CODE HERE ### (≈ 2 lines of code)
    dw = 1 / m * np.dot(X, (A - Y).T)
    db = 1 / m * np.sum(A - Y)
    ### END CODE HERE ###

    assert(dw.shape == w.shape)
    assert(db.dtype == float)
    cost = np.squeeze(cost)
    assert(cost.shape == ())

    grads = {"dw": dw,
             "db": db}

    return grads, cost

w, b, X, Y = np.array([[1],[2]]), 2, np.array([[1,2],[3,4]]), np.array([[1,0]])
grads, cost = propagate(w, b, X, Y)
print ("dw = " + str(grads["dw"]))
print ("db = " + str(grads["db"]))
print ("cost = " + str(cost))

輸出:dw = [[ 0.]
[ 0.]]
db = 0.0
cost = 12.0001295464

用梯度下降的方法進行優化
通過最小化損失函式J,學習引數w,b。對於引數P,
更新法則是P=P - a dP,在這裡a是學習速率

# GRADED FUNCTION: optimize

def optimize(w, b, X, Y, num_iterations, learning_rate, print_cost = False):
    """
    This function optimizes w and b by running a gradient descent algorithm

    Arguments:
    w -- weights, a numpy array of size (num_px * num_px * 3, 1)
    b -- bias, a scalar
    X -- data of shape (num_px * num_px * 3, number of examples)
    Y -- true "label" vector (containing 0 if non-cat, 1 if cat), of shape (1, number of examples)
    num_iterations -- number of iterations of the optimization loop
    learning_rate -- learning rate of the gradient descent update rule
    print_cost -- True to print the loss every 100 steps

    Returns:
    params -- dictionary containing the weights w and bias b
    grads -- dictionary containing the gradients of the weights and bias with respect to the cost function
    costs -- list of all the costs computed during the optimization, this will be used to plot the learning curve.

    Tips:
    You basically need to write down two steps and iterate through them:
        1) Calculate the cost and the gradient for the current parameters. Use propagate().
        2) Update the parameters using gradient descent rule for w and b.
    """

    costs = []

    for i in range(num_iterations):


        # Cost and gradient calculation (≈ 1-4 lines of code)
        ### START CODE HERE ### 
        grads, cost = propagate(w, b, X, Y)
        ### END CODE HERE ###

        # Retrieve derivatives from grads
        dw = grads["dw"]
        db = grads["db"]

        # update rule (≈ 2 lines of code)
        ### START CODE HERE ###
        w = w - learning_rate * dw
        b = b - learning_rate * db
        ### END CODE HERE ###

        # Record the costs
        if i % 100 == 0:
            costs.append(cost)

        # Print the cost every 100 training examples
        if print_cost and i % 100 == 0:
            print ("Cost after iteration %i: %f" %(i, cost))

    params = {"w": w,
              "b": b}

    grads = {"dw": dw,
             "db": db}

    return params, grads, costs

params, grads, costs = optimize(w, b, X, Y, num_iterations= 100, learning_rate = 0.009, print_cost = False)

print ("w = " + str(params["w"]))
print ("b = " + str(params["b"]))
print ("dw = " + str(grads["dw"]))
print ("db = " + str(grads["db"]))
print(costs)

輸出:w = [[ 1.]
[ 2.]]
b = 2.0
dw = [[ 0.]
[ 0.]]
db = 0.0
[12.000129546384411]

通過w和b預測X的標籤

  1. 計算這裡寫圖片描述
  2. 以0.5為閾值,預測X的標籤。
# GRADED FUNCTION: predict

def predict(w, b, X):
    '''
    Predict whether the label is 0 or 1 using learned logistic regression parameters (w, b)

    Arguments:
    w -- weights, a numpy array of size (num_px * num_px * 3, 1)
    b -- bias, a scalar
    X -- data of size (num_px * num_px * 3, number of examples)

    Returns:
    Y_prediction -- a numpy array (vector) containing all predictions (0/1) for the examples in X
    '''

    m = X.shape[1]
    Y_prediction = np.zeros((1,m))
    w = w.reshape(X.shape[0], 1)

    # Compute vector "A" predicting the probabilities of a cat being present in the picture
    ### START CODE HERE ### (≈ 1 line of code)
    A = sigmoid(np.dot(w.T, X) + b)
    ### END CODE HERE ###

    for i in range(A.shape[1]):

        # Convert probabilities A[0,i] to actual predictions p[0,i]
        ### START CODE HERE ### (≈ 4 lines of code)
        if A[0, i] <= 0.5:
            Y_prediction[0, i] = 0
        else:
            Y_prediction[0, i] = 1
        ### END CODE HERE ###

    assert(Y_prediction.shape == (1, m))

    return Y_prediction

print ("predictions = " + str(predict(w, b, X)))

輸出:predictions = [[ 1. 1.]]

你需要記住的是,你可以實現一系列的函式

  • 初始化(w,b)
  • 從學習到的(w,b)當中最優化
    計算損失函式和它的梯度
    利用梯度下降更新引數
  • 根據學習到的(w,b)預測樣本集的標籤

5 將所有函式集合在模型當中

利用先前的符號,實現模型函式

  • Y_prediction 用於預測測試集
  • Y_prediction_train 用於預測訓練集
  • w, costs, grads 是最優化函式optimize()的輸出
# GRADED FUNCTION: model

def model(X_train, Y_train, X_test, Y_test, num_iterations = 2000, learning_rate = 0.5, print_cost = False):
    """
    Builds the logistic regression model by calling the function you've implemented previously

    Arguments:
    X_train -- training set represented by a numpy array of shape (num_px * num_px * 3, m_train)
    Y_train -- training labels represented by a numpy array (vector) of shape (1, m_train)
    X_test -- test set represented by a numpy array of shape (num_px * num_px * 3, m_test)
    Y_test -- test labels represented by a numpy array (vector) of shape (1, m_test)
    num_iterations -- hyperparameter representing the number of iterations to optimize the parameters
    learning_rate -- hyperparameter representing the learning rate used in the update rule of optimize()
    print_cost -- Set to true to print the cost every 100 iterations

    Returns:
    d -- dictionary containing information about the model.
    """

    ### START CODE HERE ###

    # initialize parameters with zeros (≈ 1 line of code)
    w, b = initialize_with_zeros(X_train.shape[0])

    # Gradient descent (≈ 1 line of code)
    parameters, grads, costs = optimize(w, b, X_train, Y_train, num_iterations, learning_rate, print_cost)

    # Retrieve parameters w and b from dictionary "parameters"
    w = parameters["w"]
    b = parameters["b"]

    # Predict test/train set examples (≈ 2 lines of code)
    Y_prediction_test = predict(w, b, X_test)
    Y_prediction_train = predict(w, b, X_train)

    ### END CODE HERE ###

    # Print train/test Errors
    print("train accuracy: {} %".format(100 - np.mean(np.abs(Y_prediction_train - Y_train)) * 100))
    print("test accuracy: {} %".format(100 - np.mean(np.abs(Y_prediction_test - Y_test)) * 100))


    d = {"costs": costs,
         "Y_prediction_test": Y_prediction_test, 
         "Y_prediction_train" : Y_prediction_train, 
         "w" : w, 
         "b" : b,
         "learning_rate" : learning_rate,
         "num_iterations": num_iterations}

    return d

執行下面的程式,來訓練你的模型

d = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations = 2000, learning_rate = 0.005, print_cost = True)

輸出:Cost after iteration 0: 144.867761
Cost after iteration 100: 144.867761
Cost after iteration 200: 144.867761
Cost after iteration 300: 144.867761
Cost after iteration 400: 144.867761
Cost after iteration 500: 144.867761
Cost after iteration 600: 144.867761
Cost after iteration 700: 144.867761
Cost after iteration 800: 144.867761
Cost after iteration 900: 144.867761
Cost after iteration 1000: 144.867761
Cost after iteration 1100: 144.867761
Cost after iteration 1200: 144.867761
Cost after iteration 1300: 144.867761
Cost after iteration 1400: 144.867761
Cost after iteration 1500: 144.867761
Cost after iteration 1600: 144.867761
Cost after iteration 1700: 144.867761
Cost after iteration 1800: 144.867761
Cost after iteration 1900: 144.867761
train accuracy: 65.5502392344 %
test accuracy: 34.0 %

改變索引值,觀察對測試集的預測

# Example of a picture that was wrongly classified.
index = 1
plt.imshow(test_set_x[:,index].reshape((num_px, num_px, 3)))
print ("y = " + str(test_set_y[0,index]) + ", you predicted that it is a \"" + classes[int(d["Y_prediction_test"][0,index])].decode("utf-8") +  "\" picture.")

輸出:y = 1, you predicted that it is a “cat” picture.

我們還可以畫出成本函式和梯度。

# Plot learning curve (with costs)
costs = np.squeeze(d['costs'])
plt.plot(costs)
plt.ylabel('cost')
plt.xlabel('iterations (per hundreds)')
plt.title("Learning rate =" + str(d["learning_rate"]))
plt.show()

這裡寫圖片描述
解釋
可以看到損失函式在下降。它顯示了這些引數正在被學習。但是,也可以看到,在訓練集上對模型進行更多的訓練,嘗試增加單元中的迭代次數,並重新執行單元格。可能會看到訓練集的準確性提高了,但是測試集的準確性下降了。這就是所謂的過度擬合。

6 進一步的分析

學習速率對其的影響。學習速率過大可能會錯過最佳值,學習速率過慢,可能會導致迭代次數過多。

下面對比,在不同學習速率下,對結果的影響。

learning_rates = [0.01, 0.001, 0.0001]
models = {}
for i in learning_rates:
    print ("learning rate is: " + str(i))
    models[str(i)] = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations = 1500, learning_rate = i, print_cost = False)
    print ('\n' + "-------------------------------------------------------" + '\n')

for i in learning_rates:
    plt.plot(np.squeeze(models[str(i)]["costs"]), label= str(models[str(i)]["learning_rate"]))

plt.ylabel('cost')
plt.xlabel('iterations')

legend = plt.legend(loc='upper center', shadow=True)
frame = legend.get_frame()
frame.set_facecolor('0.90')
plt.show()

輸出:learning rate is: 0.01
train accuracy: 99.52153110047847 %
test accuracy: 68.0 %

learning rate is: 0.001
train accuracy: 88.99521531100478 %
test accuracy: 64.0 %

learning rate is: 0.0001
train accuracy: 68.42105263157895 %
test accuracy: 36.0 %

這裡寫圖片描述

解釋

  • 不同的學習速率將會有不同的代價函式,因此有不同的預測結果。
  • 學習速率太大(0.01),代價函式可能出現最大的波動。
  • 代價函式太低,要注意過多你喝的發生。
  • 在深度學習中推薦
    降低代價函式的學習速率。
    如果模型出現過擬合,我們可以採用其他方法降低過擬合。

7 測試自己的模型

## START CODE HERE ## (PUT YOUR IMAGE NAME) 
my_image = "cat_in_iran.jpg"   # change this to the name of your image file 
## END CODE HERE ##

# We preprocess the image to fit your algorithm.
fname = "images/" + my_image
image = np.array(ndimage.imread(fname, flatten=False))
my_image = scipy.misc.imresize(image, size=(num_px,num_px)).reshape((1, num_px*num_px*3)).T
my_predicted_image = predict(d["w"], d["b"], my_image)

plt.imshow(image)
print("y = " + str(np.squeeze(my_predicted_image)) + ", your algorithm predicts a \"" + classes[int(np.squeeze(my_predicted_image)),].decode("utf-8") +  "\" picture.")

輸出:y = 1.0, your algorithm predicts a “cat” picture.

我們在這次的作業中需要意識到

  1. 對資料集的預處理很重要。
  2. 獨立實現每一個函式(initialize(), propagate(), optimize()),然後構建你的模型model()。
  3. 學習速率將會對演算法產生巨大的影響。

另外的練習

  • 試驗學習速率和迭代次數的關係。
  • 嘗試不同的初始化方式,並比較其影響。
  • 測試其他的預處理(資料中心,或者按其標準偏差劃分每一行)

相關推薦

神經網路深度學習神經網路基礎第二課後作業——神經網路思維邏輯迴歸

歡迎來到你的第一個程式設計作業,在這次作業中你將會用邏輯迴歸去識別一個貓。並且在這次作業中你將會用神經網路的思維去一步一步的去解決這個問題和磨練你的深度學習的直覺。 說明: 在你的程式碼中不能使用for或while迴圈,除非說明明確要你這麼做。 你將會

神經網路深度學習神經網路基礎第二課後作業——Python與Numpy基礎知識

1 用numpy 建立基本函式 1.1 s型函式,np.exp() # GRADED FUNCTION: basic_sigmoid import math def basic_sigmoid(x): """ Compute

深度學習群卷積Group Convolution

最近在看MSRA的王井東研究員的《Interleaved Group Convolutions for Deep Neural Networks》。論文中多次提到群卷積這個概念,所以特地學習了一下群卷積。 群卷積最早出現於AlexNet中。是為了解決視訊記

神經網路深度學習神經網路基礎第三課後作業——一個隱藏層的平面資料分類

由於沒有找到課後練習,所有練習文章均參考點選開啟連結,我已經將所有程式碼都實現過一遍了,沒有錯誤,感謝博主歡迎來到第三週的課程,在這一週的任務裡,你將建立一個只有一個隱含層的神經網路。相比於之前你實現的邏輯迴歸有很大的不同。你將會學習一下內容:用一個隱含層的神經網路實現一個二

Deeplearning.ai吳恩達筆記神經網路深度學習1

Introduction to Deep Learning What is a neural neural network? 當對於房價進行預測時,因為我們知道房子價格是不可能會有負數的,因此我們讓面積小於某個值時,價格始終為零。 其實對於以上這麼一個預測的模型就可以看

Deeplearning.ai吳恩達筆記神經網路深度學習3

Shallow Neural Network Neural Networks Overview 同樣,反向傳播過程也分成兩層。第一層是輸出層到隱藏層,第二層是隱藏層到輸入層。其細節部分我們之後再來討論。 Neural Network Representation

深度學習筆記——神經網路深度學習淺層神經網路

1.神經網路概覽 神經網路的結構與邏輯迴歸類似,只是神經網路的層數比邏輯迴歸多一層,多出來的中間那層稱為隱藏層或中間層。從計算上來說,神經網路的正向傳播和反向傳播過程只是比邏輯迴歸多了一次重複的計算。正向傳播過程分成兩層,第一層是輸入層到隱藏層,用上標[1]來表示;第二層是隱藏層到輸出層,用上標

吳恩達第一門-神經網路深度學習第二6-10學習筆記

神經網路和深度學習第二週6-10學習筆記 6.更多導數的例子 在本節中,為上一節的導數學習提供更多的例子。在上一節中,我們複習了線性函式的求導方法,其導數值在各點中是相等的。本節以y=a^2這一二次函式為例,介紹了導數值在各點處發生變化時的求導方法。求導大家都會,y=x ^3的導數是

神經網路深度學習基本原理

這是看到的一篇對神經網路的講解的文章,我覺得寫得很好,也仔細學習了學習,最近我可能也得用這個東西,現在確實是很火啊,也很實用。   神經網路和深度學習 神經網路:一種可以通過觀測資料使計算機學習的仿生語言範例 深度學習:一組強大的神經網路學習技術  

吳恩達第一門-神經網路深度學習第三6-10學習筆記

吳恩達第一門-神經網路和深度學習第三週6-10學習筆記 3.6啟用函式 啟用函式 圖中給出了前面課程中所學到的利用神經網路計算輸出值的具體步驟。其中的 σ

吳恩達《神經網路深度學習》課程筆記歸納-- 神經網路基礎邏輯迴歸

上節課我們主要對深度學習(Deep Learning)的概念做了簡要的概述。我們先從房價預測的例子出發,建立了標準的神經網路(Neural Network)模型結構。然後從監督式學習入手,介紹了Standard NN,CNN和RNN三種不同的神經網路模型。接著介紹了兩種不

吳恩達《神經網路深度學習》課程筆記歸納-- 神經網路基礎Python與向量化

上節課我們主要介紹了邏輯迴歸,以輸出概率的形式來處理二分類問題。我們介紹了邏輯迴歸的Cost function表示式,並使用梯度下降演算法來計算最小化Cost function時對應的引數w和b。通過計算圖的方式來講述了神經網路的正向傳播和反向傳播兩個過程。本節課我們將來

01神經網路深度學習-Deep Neural Network for Image Classification: Application-第四周程式設計作業2

一、兩層神經網路 模型:LINEAR->RELU->LINEAR->SIGMOID #coding=utf-8 import time import numpy as np import h5py import matplotlib.pyplot as

Andrew Ng——神經網路深度學習——第二筆記

Week2 2-1二分分類 計算機如何儲存一張圖片? 計算機要儲存一張圖片,實質上是要儲存三個矩陣,這三個矩陣分別對應RGB(red,green,blue)三個顏色的通道。例如輸入的圖片是64×64畫素的,那麼每一個矩陣的的大小就是64×64的,所以計算機就儲存了3個6

Lesson1:神經網路深度學習

能夠使神經網路執行速度加快的幾個Python技巧 vectorization:避免在神經網路中使用for迴圈 broadcast:避免在神經網路中使用for迴圈 申明變數時,將變數初始化為(m,n)的形式,而不是(m,)形式 import numpy a

神經網路深度學習—— 反向傳播工作原理

本文轉自:https://blog.csdn.net/qq_31192383/article/details/77198870 反向傳播演算法工作原理 在上一篇文章,我們看到了神經網路如何通過梯度下降演算法學習,從而改變權重和偏差。但是,前面我們並沒有討論如何計算代價函

神經網路深度學習-學習總結

     粗略地說,交叉熵是“不確定性”的一種度量。特別地,我們的神經元想要計算函式x-> y = y(x)。但是,它用函式x->a = a(x) 進行了替換。假設我們將a 想象成我們神經元估計為y = 1 的概率,而1-a 則是y = 0 的概率。那麼交叉熵衡量我們學習到y的正確值的平均起來的不

Coursera-吳恩達-深度學習-神經網路深度學習-week1-測驗

本文章內容: Coursera吳恩達深度學習課程,第一課神經網路和深度學習Neural Networks and Deep Learning, 第一週:深度學習引言(Introduction to Deep Learning) 部分的測驗,題目及答案截圖。 正確:ABC

吳恩達Coursera深度學習課程筆記1-1神經網路深度學習-深度學習概論

這系列文章是我在學習吳恩達教授深度學習課程時為了加深自己理解,同時方便後來對內容進行回顧而做的筆記,其中難免有錯誤的理解和不太好的表述方式,歡迎各位大佬指正並提供建議。1、什麼是神經網路               在簡單的從房屋面積預測價格時,神經網路可以理解為將輸入的房屋

神經網路深度學習】筆記

文章導讀: 1.交叉熵損失函式   1.1 交叉熵損失函式介紹   1.2 在MNIST數字分類上使用交叉熵損失函式   1.3 交叉熵的意義以及來歷   1.4 Softmax 2. 過擬合和正則化   2.1 過擬合   2.2 正則化   2.3 為什麼正則化可以減輕