เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ทดลองสร้างเครือข่ายที่กว้างขึ้น

ตอนนี้คุณมีความรู้พร้อมสำหรับการทดลองสร้างโมเดลในรูปแบบต่างๆ แล้ว!

โมเดลชื่อ model_1 ถูกโหลดไว้ให้แล้ว โดยสามารถดูสรุปข้อมูลของโมเดลนี้ได้ใน IPython Shell ซึ่งเป็นเครือข่ายขนาดเล็ก มี hidden layer ละ 10 units เท่านั้น

ในแบบฝึกหัดนี้ จะสร้างโมเดลใหม่ชื่อ model_2 ที่มีโครงสร้างคล้ายกับ model_1 แต่เพิ่มจำนวน units เป็น 100 ใน hidden layer แต่ละชั้น

เมื่อสร้าง model_2 เสร็จแล้ว โมเดลทั้งสองจะถูก fit และแสดงกราฟเปรียบเทียบค่า loss ของแต่ละโมเดลในแต่ละ epoch เราได้เพิ่ม argument verbose=False ในคำสั่ง fit เพื่อลดการแสดงผลระหว่างการฝึก เนื่องจากจะดูผลลัพธ์ผ่านกราฟแทน

เนื่องจากต้อง fit โมเดลสองตัว จึงอาจใช้เวลาสักครู่กว่าจะเห็นผลลัพธ์หลังจากรันโค้ด โปรดรอสักครู่

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Deep Learning in Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • สร้าง model_2 ให้มีโครงสร้างเหมือน model_1 แต่เปลี่ยนจำนวนโหนดเป็น 100 แทน 10 สำหรับ Dense layer สองชั้นแรกที่ใช้ activation 'relu' และใช้ 2 โหนดสำหรับ Dense output layer โดยกำหนด activation เป็น 'softmax'
  • Compile model_2 เหมือนกับที่ทำกับโมเดลก่อนหน้า: ใช้ 'adam' เป็น optimizer, 'categorical_crossentropy' สำหรับ loss และ metrics=['accuracy']
  • กด ส่งคำตอบ เพื่อ fit โมเดลทั้งสองและดูกราฟเปรียบเทียบว่าโมเดลใดให้ผลลัพธ์ที่ดีกว่า สังเกต keyword argument verbose=False ใน model.fit() ซึ่งช่วยลดการแสดงผลระหว่างการฝึก เนื่องจากจะประเมินผลโมเดลผ่านกราฟแทนข้อความ

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Define early_stopping_monitor
early_stopping_monitor = EarlyStopping(patience=2)

# Create the new model: model_2
model_2 = ____

# Add the first and second layers
____.____(____(____, ____=____, input_shape=input_shape))
____

# Add the output layer
____

# Compile model_2
____

# Fit model_1
model_1_training = model_1.fit(predictors, target, epochs=15, validation_split=0.2, callbacks=[early_stopping_monitor], verbose=False)

# Fit model_2
model_2_training = model_2.fit(predictors, target, epochs=15, validation_split=0.2, callbacks=[early_stopping_monitor], verbose=False)

# Create the plot
plt.plot(model_1_training.history['val_loss'], 'r', model_2_training.history['val_loss'], 'b')
plt.xlabel('Epochs')
plt.ylabel('Validation score')
plt.show()
แก้ไขและรันโค้ด