ValueError:未知层:Functional。为什么?

时间:2020-09-02 22:17:47

标签: python keras deep-learning speech-to-text sequence-modeling

大家好。 现在这是一个艰难的过程。我正在研究语音识别,而这一切都发生在我在github上找到的CTCModel类内。

我训练模型,将权重另存为.h5文件,并将体系结构保存在json文件中。 在Keras 2.4.0上一切似乎都正常运行

当我预测到我会遇到很多错误并降级到Keras 2.3.0

当我尝试加载模型时,它确实在Keras 2.4上加载,但无法预测。因此我降级到2.3,它将无法加载,并且标题(ValueError: Unknown layer: Functional)出现错误。

已保存的json模型的第一行:

{"class_name": "Functional", "config"...

这是我的模型结构:

def final_model(input_dim, units, output_dim, padding_value):
    """ Build a bidirectional recurrent network for speech
    """
    # Main acoustic input
    input_data = Input(name='the_input', shape=(None, input_dim))
    masked_input = Masking(mask_value = padding_value)(input_data)

    # =============== 1st Layer =============== #
    # Add bidirectional recurrent layer
    bidirectional_rnn = Bidirectional(GRU(units, activation=None, return_sequences=True, implementation=2, name='bidir_rnn'))(masked_input)
    # Add batch normalization
    batch_normalization = BatchNormalization(name = "batch_normalization_bidirectional_rnn")(bidirectional_rnn)
    # Add activation function
    activation = Activation('relu')(batch_normalization)
    # Add dropout
    drop = Dropout(rate = 0.5)(activation)

    # =============== 2nd Layer =============== #
    # Add bidirectional recurrent layer
    bidirectional_rnn = Bidirectional(GRU(units, activation=None, return_sequences=True, implementation=2, name='bidir_rnn'))(activation)
    # Add batch normalization
    batch_normalization = BatchNormalization(name = "batch_normalization_bidirectional_rnn_2")(bidirectional_rnn)
    # Add activation function
    activation = Activation('relu')(batch_normalization)
    # Add dropout
    drop = Dropout(rate = 0.5)(activation)
    
    # =============== 3rd Layer =============== #
    # Add a TimeDistributed(Dense(output_dim)) layer
    time_dense = TimeDistributed(Dense(output_dim))(activation)
    # Add softmax activation layer
    y_pred = Activation('softmax', name='softmax')(time_dense)

    model = CTCModel.CTCModel([input_data], [y_pred])
    model.compile(Adam(lr=0.0001))
    
    model.summary()
    return model

0 个答案:

没有答案