为 CNN 添加填充
填充可以让卷积层保留其输入的分辨率。具体做法是在输入图像的边缘补零,这样卷积核就能覆盖到图像边缘的像素。
本练习是课程的一部分
使用 Keras 进行图像建模
练习说明
添加一个 Conv2D 层,并选择一种填充方式,使得输出与输入的尺寸相同。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Initialize the model
model = Sequential()
# Add the convolutional layer
model.add(____(10, kernel_size=3, activation='relu',
input_shape=(img_rows, img_cols, 1),
____))
# Feed into output layer
model.add(Flatten())
model.add(Dense(3, activation='softmax'))