ฟังก์ชันการกระตุ้น

Deep Learning เบื้องต้นด้วย Keras

Miguel Esteban

Data Scientist & Founder

Deep Learning เบื้องต้นด้วย Keras

Deep Learning เบื้องต้นด้วย Keras

Deep Learning เบื้องต้นด้วย Keras

Deep Learning เบื้องต้นด้วย Keras

Deep Learning เบื้องต้นด้วย Keras

ผลกระทบของฟังก์ชันการกระตุ้น

Deep Learning เบื้องต้นด้วย Keras

Deep Learning เบื้องต้นด้วย Keras

Deep Learning เบื้องต้นด้วย Keras

จะเลือกฟังก์ชันการกระตุ้นตัวไหนดี?

  • ไม่มีสูตรสำเร็จ
  • แต่ละฟังก์ชันมีคุณสมบัติต่างกัน
  • ขึ้นอยู่กับปัญหาที่ต้องแก้
  • และเป้าหมายของแต่ละเลเยอร์
  • ReLU เป็นตัวเลือกแรกที่ดี
  • ไม่แนะนำให้ใช้ Sigmoid ในโมเดลที่ลึก
  • ปรับแต่งด้วยการทดลอง

Deep Learning เบื้องต้นด้วย Keras

เปรียบเทียบฟังก์ชันการกระตุ้น

# Set a random seed
np.random.seed(1)

# Return a new model with the given activation def get_model(act_function): model = Sequential() model.add(Dense(4, input_shape=(2,), activation=act_function)) model.add(Dense(1, activation='sigmoid')) return model
Deep Learning เบื้องต้นด้วย Keras

เปรียบเทียบฟังก์ชันการกระตุ้น

# Activation functions to try out
activations = ['relu', 'sigmoid', 'tanh']

# Dictionary to store results
activation_results = {}

for funct in activations: model = get_model(act_function=funct) history = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=100, verbose=0) activation_results[funct] = history
Deep Learning เบื้องต้นด้วย Keras

เปรียบเทียบฟังก์ชันการกระตุ้น

import pandas as pd

# Extract val_loss history of each activation function
val_loss_per_funct = {k:v.history['val_loss'] for k,v in activation_results.items()}

# Turn the dictionary into a pandas dataframe val_loss_curves = pd.DataFrame(val_loss_per_funct)
# Plot the curves val_loss_curves.plot(title='Loss per Activation function')
Deep Learning เบื้องต้นด้วย Keras

มาฝึกกันเถอะ!

Deep Learning เบื้องต้นด้วย Keras

Preparing Video For Download...