简体   繁体   English

在 Keras LSTM 中添加双向会导致 RuntimeError('您必须在使用之前编译模型。')

[英]Adding Bidirectional in a Keras LSTM results in a RuntimeError('You must compile your model before using it.')

I'm doing:我正在做:

self.model.add(Bidirectional(LSTM(lstm1_size, input_shape=(
        seq_length, feature_dim), return_sequences=True)))
self.model.add(Bidirectional(LSTM(lstm2_size, return_sequences=True)))
self.model.add(Bidirectional(LSTM(lstm3_size, return_sequences=True)))
self.model.add(Bidirectional(LSTM(lstm4_size, return_sequences=True)))
self.model.add(Dense(feature_dim, activation='relu'))

and I get the error:我得到错误:

RuntimeError('You must compile your model before using it.')

However, when I do the same thing without the Bidirectional , it works fine.但是,当我在没有Bidirectional的情况下做同样的事情时,它工作正常。 What am I doing wrong?我究竟做错了什么?

it seems like a bug in your case because I tried the same its working normally.在您的情况下,这似乎是一个错误,因为我尝试过相同的工作正常。

import tensorflow as tf
from tensorflow.keras import Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM, Bidirectional

lstm1_size = 4
seq_length = 2
lstm2_size = 4
feature_dim = 1
lstm3_size = 4
lstm4_size = 4
model = Sequential()
model.add(Bidirectional(LSTM(lstm1_size, input_shape=(
        seq_length, feature_dim), return_sequences=True)))
model.add(Bidirectional(LSTM(lstm2_size, return_sequences=True)))
model.add(Bidirectional(LSTM(lstm3_size, return_sequences=True)))
model.add(Bidirectional(LSTM(lstm4_size, return_sequences=True)))
model.add(Dense(feature_dim, activation='relu'))

model.compile(loss='mean_squared_error', optimizer='adam')

please check if model is compiled within/outside class?请检查模型是否在类内/外编译? if problem is solved already, please let us know as well.如果问题已经解决,也请告诉我们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras编码器 - 解码器模型RuntimeError:您必须在使用之前编译模型 - Keras encoder-decoder model RuntimeError: You must compile your model before using it 合并Conv2D和Dense模型会导致“ RuntimeError:您必须在使用模型之前对其进行编译。”,尽管已编译了合并模型 - Merging Conv2D and Dense models results in “RuntimeError: You must compile your model before using it.”, despite having compiled the merged model keras “您必须在使用前编译您的 model。” 即使在编译之后 - keras “You must compile your model before using it.” even after compilation 错误“在使用它之前必须编译模型”,如果是Keras中的LSTM和fit_generator - Error “You must compile your model before using it” in case of LSTM and fit_generator in Keras Keras:尽管使用了 compile(),但“使用前必须编译模型” - Keras: “must compile model before using it” despite compile() is used 可能在Keras的CNN之前添加双向LSTM吗? - Possible to add a bidirectional LSTM before a CNN in Keras? 在Keras中加载保存的模型(双向LSTM) - Loading saved model (Bidirectional LSTM) in Keras Keras中具有批量归一化的双向LSTM - Bidirectional LSTM with Batch Normalization in Keras Keras LSTM 模型没有产生相同的结果 - Keras LSTM model not producing same results Python:gensim:RuntimeError:在训练模型之前必须首先构建词汇表 - Python: gensim: RuntimeError: you must first build vocabulary before training the model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM