我正在尝试遵循可通过此链接访问的以下教程。
在第三个标题“3. 可视化每个过滤器的激活图”下,我们可以看到以下功能:
def apply_filter(img, index, filter_list, ax):
# set the weights of the filter in the convolutional layer to filter_list[i]
model.layers[0].set_weights([np.reshape(filter_list[i], (4,4,1,1)), np.array([0])])
# plot the corresponding activation map
ax.imshow(np.squeeze(model.predict(np.reshape(img, (1, img.shape[0], img.shape[1], 1)))), cmap='gray')
我明白他们想要做什么。他们正在应用过滤器并尝试在此之后显示输出。但是,我不明白的是以下行:
model.layers[0].set_weights([np.reshape(filter_list[i], (4,4,1,1)), np.array([0])])
在这里分配权重是什么意思,为什么他们要重新塑造属于 to 的过滤4*4器4*4*1*1?