用于图像分类的卷积网络
用于分类的卷积网络由一系列卷积层(用于图像处理)和全连接(Dense)层(用于读出)构成。本练习中,您将构建一个小型卷积网络,用于对 fashion 数据集中的数据进行分类。
本练习是课程的一部分
使用 Keras 进行图像建模
练习说明
- 添加一个
Conv2D层,作为网络的输入层。使用 3×3 的卷积核。您可以使用工作区中提供的img_rows和img_cols对象来定义该层的input_shape。 - 添加一个
Flatten层,用于在网络的图像处理部分与分类部分之间进行转换。 - 添加一个
Dense层,用于对数据集中 3 类不同的服装进行分类。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the necessary components from Keras
from keras.models import Sequential
from keras.layers import Dense, Conv2D, Flatten
# Initialize the model object
model = Sequential()
# Add a convolutional layer
model.add(____(10, kernel_size=____, activation='relu',
input_shape=____))
# Flatten the output of the convolutional layer
model.add(____())
# Add an output layer for the 3 categories
model.add(____(____, activation='softmax'))