從已訓練的網路擷取卷積核
解讀模型的一種方法,是檢視卷積層中卷積核(kernel)的性質。這個練習中,你將從一個卷積式神經網路擷取其中一個卷積核,該網路的權重已儲存在一個 hdf5 檔案中。
本練習屬於課程
使用 Keras 進行影像建模
練習說明
- 從檔案
weights.hdf5將權重載入模型。 - 透過
layers屬性取得模型中的第一個卷積層。 - 使用
.get_weights()方法擷取此層的權重。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the weights into the model
model.____('weights.hdf5')
# Get the first convolutional layer from the model
c1 = model.____[0]
# Get the weights of the first convolutional layer
weights1 = c1.____()
# Pull out the first channel of the first kernel in the first layer
kernel = weights1[0][...,0, 0]
print(kernel)