我有一个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)。答案如下:https://blog.thoughtram.io/angular/2015/06/29/shadow-dom-strategies-in-angular2.html
最终的致密层创建如下:
x = keras.layers.Dense(512)(x)
outputs = keras.layers.Dense(
368, activation='sigmoid', name='predictions')(x)
那么为什么它们有超过512个输出?我该如何更改呢?
答案 0 :(得分:1)
根据您的应用程序,您可以在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
答案 1 :(得分:0)
这是Conv2D
层。卷积层产生长度为9的38x5输出,然后您的Dense
层将38x5长度为9的每个序列作为输入,并将其转换为长度为512的序列作为输出。
要摆脱空间依赖性,您需要使用诸如池层之类的东西,可能是GlobalMaxPool2D
。这样会将数据仅合并到通道维中,并生成(None, 9)
形状的输出,这将根据Dense
层得出您期望的形状。