keras:有状态网络中的reset_states()

时间:2018-06-24 16:56:44

标签: python python-3.x keras lstm

我有以下LSTM网络设置:

.list-group {
  display: none;
  width: 350px;
  height: 100%;
  position: fixed;
  top: 0;
  right: 0;
  background: #303030;
  opacity: 0.95;
  border-color: transparent;
  border: none;
}

返回:

  

“ KerasClassifier”对象没有属性“ reset_states”

问题1:Keras 2.2.0是否不再支持.reset_states()?我在文档中找不到线索。

相反,我也可以这样做:

...
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from keras.utils import np_utils
...

dim = 10
time = 20
batch_size = 20

def baseline_model():
    model = Sequential()
    model.add(LSTM(12, stateful=True, batch_input_shape=(batch_size, time, dim)))
    model.add(Dense(3, activation='softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model

model = KerasClassifier(build_fn=baseline_model, batch_size=batch_size, shuffle=False)

for i in range(100):
    model.fit(X_train, y_train, epochs=1)
    model.reset_states()

0 个答案:

没有答案