python - Keras 编码器-解码器模型 RuntimeError: You must compile your model before using it
问题描述
我正在尝试重现图像字幕模型的结果,但出现此错误。两种模型的代码如下:
image_model = Sequential()
image_model.add(Dense(EMBEDDING_DIM, input_dim=4096, activation='relu'))
image_model.add(RepeatVector(self.max_length))
lang_model = Sequential()
lang_model.add(Embedding(self.vocab_size, 256, input_length=self.max_length))
lang_model.add(LSTM(256, return_sequences=True))
lang_model.add(TimeDistributed(Dense(EMBEDDING_DIM)))
model = Sequential()
model.add(Concatenate([image_model, lang_model]))
model.add(LSTM(1000, return_sequences=False))
model.add(Dense(self.vocab_size))
model.add(Activation('softmax'))
print ("Model created!")
model.compile(loss='categorical_crossentropy',
optimizer='rmsprop', metrics=['accuracy'])
然后由以下代码调用模型:
sd = SceneDesc.scenedesc()
model = sd.create_model()
batch_size = 512
model.fit_generator(sd.data_process(batch_size=batch_size),
steps_per_epoch=sd.no_samples/batch_size, epochs=epoch, verbose=2,
callbacks=None)
但是,当fit_generator
调用 时,会引发特定错误。模型的串联有什么问题吗?
解决方案
推荐阅读
- flutter - 如何发送信息在颤动中抛出深层链接
- asp.net-core - 如何在布局图标中显示购物车项目
- python - 对同一文件夹中的文件进行并行处理
- reactjs - × TypeError:无法读取 null 的属性“名称”
- javascript - 关于运行 WEB Rtc 示例
- c# - ClearScript V8 引擎出现错误,TypeLoadException - 无法加载 V8 接口程序集
- python - 如何克服权限错误?
- android - 未解决的参考:使用自定义 Parcelable 参数时:Jetpack Navigation
- spring - 在 JSON 响应中引用正则表达式字符串
- dmn - 通过 DMN 中的业务知识模型返回时处理 null