開始使用免費開始

用於影像分類的卷積網路

用於分類的卷積網路由一連串的卷積層(處理影像)與全連接(Dense)層(讀出)組成。在這個練習中,你將建構一個小型的卷積網路,來分類時尚資料集中的資料。

本練習屬於課程

使用 Keras 進行影像建模

檢視課程

練習說明

  • 新增一個 Conv2D 層作為網路的輸入層。使用 3 乘 3 的卷積核大小。你可以使用工作區中提供的 img_rowsimg_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'))
編輯並執行程式碼