開始使用免費開始

比較啟動函式

比較啟動函式需要寫一點程式碼,但你一定做得到!

你會在第 2 章為農場灌溉機建立的 multi-label 模型 上嘗試不同的啟動函式。函式 get_model('relu') 會回傳這個模型的複本,並將隱藏層的啟動函式設為 'relu'

你會迴圈跑過多種啟動函式,為每個函式產生一個新模型並進行訓練。把 history 回呼物件存進字典後,你就能在下一個練習中視覺化哪個啟動函式表現最佳!

X_trainy_trainX_testy_test 都已經準備好,可直接用來訓練你的模型。

本練習屬於課程

Keras 深度學習入門

檢視課程

練習說明

  • 將啟動函式陣列填入 reluleaky_relusigmoidtanh
  • 在每次迭代中使用 get_model(),並將目前的啟動函式作為參數以取得新模型。
  • 訓練模型時提供訓練資料與 validation_data,使用 20 個 epochs,並將 verbose 設為 0。

動手互動練習

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

# Activation functions to try
activations = [____, ____, ____, ____]

# Loop over the activation functions
activation_results = {}

for act in activations:
  # Get a new model with the current activation
  model = ____
  # Fit the model and store the history results
  h_callback = ____
  activation_results[act] = h_callback
編輯並執行程式碼