[英]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.