我是深度学习的新手,我正在尝试通过在 TensorFlow Keras 中创建自己的模型来实现图像字幕。
在训练模型时,TimeDistributed 层遇到 ValueError: Shapes (None, None) and (None, 80, 14021) are incompatible
错误。有人可以帮我调试这个错误吗?
模型代码中使用的值:
Max_Length_caption = 80
vocab_len = 14021
embedding_dim = 300
input1 (dim) = (2205, 4096)
input2 (dim) = (2205, 80)
Y_hat (dim) = (2205, 14021)
这是我的模型代码:
input1 = Input(shape=(4096,))
x = Dropout(0.5)(input1)
x = Dense(units=256,activation='relu')(x)
input2 = Input(shape=(max_length_caption,))
y = Embedding(vocab_len, embedding_dim, mask_zero=True, name="embedding",)(input2)
zero_out = Lambda(lambda x: tf.zeros_like(x))(x) # generating zero_out as a cell state
y = Dropout(0.2)(y)
y = LSTM(units=256, return_sequences=True)(y, initial_state=[x, zero_out]) # passing hidden state as x and cell state as zero_out
y = Dropout(0.2)(y)
y = LSTM(units=256, return_sequences=True)(y)
outputs = TimeDistributed(Dense(units=vocab_len, activation="softmax"))(y)
model = Model(inputs=[input1, input2], outputs=outputs)
模型摘要: