开始使用免费开始使用

为您的网络添加 dropout

Dropout 是一种正则化方法,在每轮训练中会随机移除该层中不同的子集单元。在本练习中,您将把 dropout 添加到之前练习中使用的卷积神经网络中:

  1. 卷积(15 个单元,卷积核大小 2,激活函数为 'relu')
  2. Dropout(20%)
  3. 卷积(5 个单元,卷积核大小 2,激活函数为 'relu')
  4. 展平(Flatten)
  5. 全连接(Dense,3 个单元,激活函数为 'softmax')

一个顺序式 model 以及 DenseConv2DFlattenDropout 对象已在您的工作区中可用。

本练习是课程的一部分

使用 Keras 进行图像建模

查看课程

练习说明

  • 在第一层后添加 20% 的 dropout。
  • 添加一个展平层。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Add a convolutional layer
model.add(Conv2D(15, kernel_size=2, activation='relu', 
                 input_shape=(img_rows, img_cols, 1)))

# Add a dropout layer
____

# Add another convolutional layer
model.add(Conv2D(5, kernel_size=2, activation='relu'))

# Flatten and feed to output layer
____
model.add(Dense(3, activation='softmax'))
编辑并运行代码