对于一个基于深度学习的项目,我使用LSTM构建了一个sequunce2sequence模型。现在我想用GRU代替LSTM,但是我在深度学习领域没有足够的知识。我得到这个错误,无法解决。
错误消息
An `initial_state` was passed that is not compatible with `cell.state_size`. Received `state_spec`=ListWrapper([InputSpec(shape=(None, 80, 512), ndim=3), InputSpec(shape=(None, 512), ndim=2)]); however `cell.state_size` is [512]
我的代码
time_steps_encoder=80
num_encoder_tokens=4096
latent_dim=512
time_steps_decoder=10
num_decoder_tokens=1500
batch_size=320
# Setting up the encoder
encoder_inputs = Input(shape=(time_steps_encoder, num_encoder_tokens), name="encoder_inputs")
encoder = GRU(latent_dim, return_state=True,return_sequences=True, name='endcoder')
state_h, state_c = encoder(encoder_inputs)
encoder_states = [state_h, state_c]
#Set up the decoder
decoder_inputs = Input(shape=(time_steps_decoder, num_decoder_tokens), name= "decoder_inputs")
decoder = GRU(latent_dim, return_sequences=True, return_state=True, name='decoder')
decoder_outputs, _ , _= decoder(decoder_inputs, initial_state=encoder_states)
decoder_dense = Dense(num_decoder_tokens, activation='softmax', name='decoder_relu')
decoder_outputs = decoder_dense(decoder_outputs)
model = Model([encoder_inputs, decoder_inputs], decoder_outputs)
model.summary()
plot_model(model, to_file='model_train.png', show_shapes=True, show_layer_names=True)
本行显示错误误差
我认为,batch_size可能是initial_states的第一个维度。换句话说,批处理中的每个元素可以以不同的initial_states开始。