- Keras 教程
- Keras - 主頁
- Keras - 簡介
- Keras - 安裝
- Keras - 後端配置
- Keras - 深度學習概述
- Keras - 深度學習
- Keras - 模組
- Keras - 層
- Keras - 自定義層
- Keras - 模型
- Keras - 模型編譯
- Keras - 模型評估和預測
- Keras - 卷積神經網路
- Keras - 使用 MPL 進行迴歸預測
- Keras - 使用 LSTM RNN 進行時間序列預測
- Keras - 應用程式
- Keras - 使用 ResNet 模型進行即時預測
- Keras - 預訓練模型
- Keras 實用資源
- Keras - 快速指南
- Keras - 實用資源
- Keras - 討論
Keras - Flatten 層
Flatten 用於扁平化輸入。例如,如果將 flatten 應用於輸入形狀為 (batch_size, 2,2) 的層,那麼該層的輸出形狀將為 (batch_size, 4)
Flatten 有一個引數,如下所示
keras.layers.Flatten(data_format = None)
data_format 是一個可選引數,它用於在從一種資料格式切換到另一種資料格式時保留權重順序。它接受 channels_last 或 channels_first 作為值。channels_last 是預設選項,它將輸入形狀標識為 (batch_size, ..., channels),而 channels_first 將輸入形狀標識為 (batch_size, channels, ...)
使用 Flatten 層的一個簡單示例如下 -
>>> from keras.models import Sequential >>> from keras.layers import Activation, Dense, Flatten >>> >>> >>> model = Sequential() >>> layer_1 = Dense(16, input_shape=(8,8)) >>> model.add(layer_1) >>> layer_2 = Flatten() >>> model.add(layer_2) >>> layer_2.input_shape (None, 8, 16) >>> layer_2.output_shape (None, 128) >>>
其中,第二層輸入形狀為 (None, 8, 16),並將其扁平化為 (None, 128)。
廣告