开始使用免费开始使用

从已训练的网络中提取卷积核

解释模型的一种方式是查看卷积层中卷积核的性质。本练习中,您将从一个卷积神经网络中提取其中一个卷积核。该网络的权重已保存在一个 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)
编辑并运行代码