How to use model.reset_states() in Keras?

后端 未结 2 1312
感情败类
感情败类 2021-02-03 11:59

I have sequential data and I declared a LSTM model which predicts y with x in Keras. So if I call model.predict(x1) and model.predic

2条回答
  •  北海茫月
    2021-02-03 12:36

    If you use explicitly either of:

    model.reset_states() 
    

    to reset the states of all layers in the model, or

    layer.reset_states() 
    

    to reset the states of a specific stateful RNN layer (also LSTM layer), implemented here:

    def reset_states(self, states=None):
      if not self.stateful:
         raise AttributeError('Layer must be stateful.')
    

    this means your layer(s) must be stateful.

    In LSTM you need to:

    • explicitly specify the batch size you are using, by passing a batch_size argument to the first layer in your model or batch_input_shape argument

    • set stateful=True.

    • specify shuffle=False when calling fit().


    The benefits of using stateful models are probable best explained here.

提交回复
热议问题