Aan de slagGa gratis aan de slag

Extracting a kernel from a trained network

One way to interpret models is to examine the properties of the kernels in the convolutional layers. In this exercise, you will extract one of the kernels from a convolutional neural network with weights that you saved in a hdf5 file.

Deze oefening maakt deel uit van de cursus

Image Modeling with Keras

Cursus bekijken

Oefeninstructies

  • Load the weights into the model from the file weights.hdf5.
  • Get the first convolutional layer in the model from the layers attribute.
  • Use the .get_weights() method to extract the weights from this layer.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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)
Code bewerken en uitvoeren