開始使用免費開始

建立自動編碼器(autoencoder)

自動編碼器有許多有趣的應用,例如異常偵測與影像去雜訊。它的目標是產生與輸入相同的輸出。輸入會被壓縮到較低維的空間,稱為編碼(encode)。接著模型會學習如何將其解碼(decode)回原始形式。

你將對手寫數字的 MNIST 資料集進行編碼與解碼。隱藏層會將影像編碼成 32 維的表示;原始影像由 784 個像素(28 x 28)組成。自動編碼器基本上會學會把 784 像素的原始影像壓縮成 32 維的表示,並用這個編碼表示重建回原本的 784 像素影像。

Sequential 模型與 Dense 層都已為你準備好。

來建立一個自動編碼器吧!

本練習屬於課程

Keras 深度學習入門

檢視課程

練習說明

  • 建立一個 Sequential 模型。
  • 新增一個密集層,其神經元數量等於編碼後影像的維度,並將 input_shape 設為原始影像的像素數。
  • 再新增最終層,其神經元數量等於輸入影像的像素數。
  • 使用 adadelta 作為最佳化器、binary_crossentropy 作為損失函式來編譯你的 autoencoder,然後列出摘要。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Start with a sequential model
autoencoder = ____

# Add a dense layer with input the original image pixels and neurons the encoded representation
autoencoder.add(____(____, input_shape=(____, ), activation="relu"))

# Add an output layer with as many neurons as the orginal image pixels
autoencoder.add(____(____, activation = "sigmoid"))

# Compile your model with adadelta
autoencoder.compile(optimizer = ____, loss = ____)

# Summarize your model structure
____
編輯並執行程式碼