始める無料で始める

学習済みネットワークからカーネルを取り出す

モデルを解釈する方法のひとつは、畳み込み層にあるカーネルの性質を調べることです。この演習では、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)
コードを編集して実行