สำรวจ Convolution
การตรวจสอบ activation ของ convolutional layer เป็นเรื่องที่น่าสนใจมาก ลองทำดูสักครั้งแล้วจะติดใจ!
ในแบบฝึกหัดนี้ คุณจะสร้างโมเดลใหม่โดยใช้ออบเจกต์ Model ของ Keras ซึ่งรับ list ของ input และ list ของ output โดย output ที่จะส่งให้โมเดลใหม่นี้คือผลลัพธ์ของ convolutional layer แรก เมื่อรับภาพตัวเลขจากชุดข้อมูล MNIST เป็น input
โมเดล convolutional model ที่สร้างไว้ในแบบฝึกหัดก่อนหน้าได้รับการ train มาให้แล้ว และสามารถจำแนกภาพลายมือจากชุดข้อมูล MNIST ได้อย่างถูกต้อง ตรวจสอบได้โดยรัน model.summary() ใน console
มาดู convolutional mask ที่โมเดลเรียนรู้ใน convolutional layer แรกกัน!
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Deep Learning เบื้องต้นด้วย Keras
คำแนะนำการฝึกหัด
- ดึง reference ของ output จาก convolutional layer แรกในโมเดล
- สร้างโมเดลใหม่โดยใช้ input ของ layer แรกของโมเดลและ
first_layer_outputเป็น output - ใช้
first_layer_modelนี้พยากรณ์ผลบนX_test - Plot activation ของตัวเลขตัวแรกใน
X_testสำหรับ neuron filter ที่ 15 และที่ 18
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Obtain a reference to the outputs of the first layer
first_layer_output = model.layers[____].output
# Build a model using the model's input and the first layer output
first_layer_model = Model(inputs = model.layers[0].input, outputs = ____)
# Use this model to predict on X_test
activations = ____.____(____)
# Plot the activations of first digit of X_test for the 15th filter
axs[0].matshow(activations[____,:,:,14], cmap = 'viridis')
# Do the same but for the 18th filter now
axs[1].matshow(activations[0,:,:,____], cmap = 'viridis')
plt.show()