def build(self, vocabs=None):
if self._keras_model:
return
if vocabs is None and self._word_vector_init is not None:
raise ValueError('If word_vector_init is not None, build method '
'must be called with vocabs that are not None!')
image_input, image_embedding = self._build_image_embedding()
sentence_input, word_embedding = self._build_word_embedding(vocabs)
sequence_input = Concatenate(axis=1)([image_embedding, word_embedding])
sequence_output = self._build_sequence_model(sequence_input)
model = Model(inputs=[image_input, sentence_input],
outputs=sequence_output)
model.compile(optimizer=Adam(lr=self._learning_rate, clipnorm=5.0),
loss=categorical_crossentropy_from_logits,
metrics=[categorical_accuracy_with_variable_timestep])
self._keras_model = model
评论列表
文章目录