InvalidArgumentError: Matrix size-incompatible: In[0]: [47,1000],
In[1]: [4096,256] [[node model_1/dense_4/Relu (defined at
<ipython-input-23-4876d7977fbf>:10) ]]
[Op:__inference_train_function_14686]
my code:
def define_model(vocab_size, max_length):
# feature extractor model
inputs1 = Input(shape=(4096,))
fe1 = Dropout(0.5)(inputs1)
fe2 = Dense(256, activation='relu')(fe1)
fe3 = RepeatVector(max_length)(fe2)
#embedding
inputs2 = Input(shape=(max_length,))
emb2 = Embedding(vocab_size,256,mask_zero =True)(inputs2)
#merge inputs
merged = concatenate([fe3, emb2])
#language model(decoder)
lm2 = LSTM(500,return_sequences=False)(merged)
#lm3 = Dense(500,activation='relu')(lm2)
outputs = Dense(vocab_size,activation='softmax')(lm2)
# tie it together [image, seq] [word]
model = Model(inputs=[inputs1, inputs2], outputs=outputs)
model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy'])
# summarize model
print(model.summary())
return model
question from:
https://stackoverflow.com/questions/65913215/i-am-doing-project-on-image-captioning-using-cnn-and-lstm-i-got-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…