[英]Dimensionality of Keras Dense layer
我有一個 Keras 模型,尺寸如下:
________________________________________________________________________________
Layer (type) Output Shape Param #
================================================================================
stft (InputLayer) (None, 1, 16384) 0
________________________________________________________________________________
static_stft (Spectrogram) (None, 1, 65, 256) 16640
________________________________________________________________________________
conv2d_1 (Conv2D) (None, 38, 5, 9) 12882
________________________________________________________________________________
dense_1 (Dense) (None, 38, 5, 512) 5120
________________________________________________________________________________
predictions (Dense) (None, 38, 5, 368) 188784
================================================================================
我對最后密集層的維度感到困惑。 我希望分別有 (None,512) 和 (None,368)。 這是由以下答案建議的: Keras lstm 和密集層
它們最終的密集層創建如下:
x = keras.layers.Dense(512)(x)
outputs = keras.layers.Dense(
368, activation='sigmoid', name='predictions')(x)
那么為什么他們有超過 512 個輸出呢? 我該如何改變這一點?
根據您的應用程序,您可以在 Conv2D 層之后展平:
input_layer = Input((1, 1710))
x = Reshape((38, 5, 9))(input_layer)
x = Flatten()(x)
x = Dense(512)(x)
x = Dense(368)(x)
Layer (type) Output Shape Param #
_________________________________________________________________
input_1 (InputLayer) [(None, 1, 1710)] 0
_________________________________________________________________
reshape (Reshape) (None, 38, 5, 9) 0
_________________________________________________________________
flatten (Flatten) (None, 1710) 0
_________________________________________________________________
dense (Dense) (None, 512) 876032
_________________________________________________________________
dense_1 (Dense) (None, 368) 188784
這是Conv2D
層。 卷積層產生長度為 9 的 38x5 輸出,然后您的Dense
層將每個 38x5 長度為 9 的序列作為輸入並將其轉換為長度為 512 的序列作為輸出。
為了擺脫空間依賴性,您需要使用池化層之類的東西,可能是GlobalMaxPool2D
。 這會將數據合並到僅通道維度中,並生成(None, 9)
形狀的輸出,這將導致來自Dense
層的預期形狀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.