使用 Keras 訓練
在這個練習中,我們回到手語字母分類的問題。我們有 2000 張代表四個字母(A、B、C、D)的影像,目標是以高準確率完成分類。我們會完成整個流程,包括模型定義、編譯與訓練。
注意:keras 已為你自 tensorflow 匯入。另外,特徵已命名為 sign_language_features,目標(標籤)已命名為 sign_language_labels。
本練習屬於課程
Python 的 TensorFlow 入門
練習說明
- 定義一個名為
model的序列式模型。 - 將輸出層設為 dense,節點數為 4,並使用
softmax活化函式。 - 使用
SGD最佳化器與categorical_crossentropy損失來編譯模型。 - 完成訓練(fit)操作,並將 epochs 設為 5。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define a sequential model
____
# Define a hidden layer
model.add(keras.layers.Dense(16, activation='relu', input_shape=(784,)))
# Define the output layer
____
# Compile the model
model.compile('____', loss='____')
# Complete the fitting operation
model.fit(____, ____, epochs=____)