在 Keras 中结合 2D CNN 和 GRU

问题描述 投票:0回答:2

我想构建这种类型的神经网络架构:2DCNN+GRU。 假设输入是一个 4D 张量 (batch_size, 1, 1500, 40),那么我有 3 个 2D-CNN 层(具有批量规范、relu、最大池化和 dropout)。 在第三个 cnn 层的输出中,我获得了一个 4D 张量 (None, 120, 1500, 1)。 现在我的问题来了,我如何将 GRU 层与这个输入形状连接起来? 我试图在 keras 中进行重塑(因此它变为(无,1500、120))并通过 gru 层提供输出,但出现了问题...... 还要考虑一下,我的训练标签是 3D 张量 (batch_size, 1500, 2)。 我在这里复制 keras 模型和 summary() 命令的输出:

    input_data = Input(shape=[1,1500,40])
    x = input_data
    for i in range(len([32,96,120])):
        x = Conv2D(filters=[32,96,120],
                   kernel_size=[5,5],
                   activation='relu',
                   padding='same'
                   )(x)
        x = BatchNormalization(axis=3)(x)
        x = Dropout(0.3)(x)
        x = MaxPooling2D(pool_size=[(1,5),(1,4),(1,2)],
                         data_format="channels_first")(x)

    x = Reshape((1500, 120))(x)

    x = GRU(units=120,
            activation='tanh',
            recurrent_activation='hard_sigmoid',
            dropout=0.3,
            recurrent_dropout=0.3,
            )(x)

    predictions = Dense(2, activation='softmax')(x)
    network = Model(input_data, predictions)
    network.summary()

Network Summary

你能帮帮我吗?谢谢

keras convolution
2个回答
1
投票

您似乎希望对输入的每个时间步进行预测。为此,您需要在创建

return_sequences
层时添加参数
True
设置为
GRU


-1
投票

我遇到了类似的错误。你能告诉我你的解决方案是什么吗?

p/s: 我不能发表评论所以我必须发表一个答案

© www.soinside.com 2019 - 2024. All rights reserved.