開始使用免費開始

修正線性啟動函式

正如 Dan 在影片中說明的,「啟動函式」是套用在每個節點上的函式。它會把節點的輸入轉換成某個輸出。

修正線性啟動函式(稱為 ReLU)已被證明能帶來效能非常高的網路。 這個函式只接受單一數值作為輸入:若輸入為負則回傳 0,若輸入為正則回傳原輸入。

以下是一些例子:
relu(3) = 3
relu(-3) = 0

本練習屬於課程

Python 深度學習入門

檢視課程

練習說明

  • 完成 relu() 函式的定義:
    • 使用 max() 函式計算 relu() 的輸出值。
  • relu() 套用在 node_0_input,計算 node_0_output
  • relu() 套用在 node_1_input,計算 node_1_output

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

def relu(input):
    '''Define your relu activation function here'''
    # Calculate the value for the output of the relu function: output
    output = max(____, ____)
    
    # Return the value just calculated
    return(output)

# Calculate node 0 value: node_0_output
node_0_input = (input_data * weights['node_0']).sum()
node_0_output = ____

# Calculate node 1 value: node_1_output
node_1_input = (input_data * weights['node_1']).sum()
node_1_output = ____

# Put node values into array: hidden_layer_outputs
hidden_layer_outputs = np.array([node_0_output, node_1_output])

# Calculate model output (do not apply relu)
model_output = (hidden_layer_outputs * weights['output']).sum()

# Print model output
print(model_output)
編輯並執行程式碼