Training and loading a saved model.
The City Of Knowledge
Welcome back. In the last session, we computed the number of parameters. And now, we're going to show how to train a stateful LSTM network. Here, you see a loop, which is going to the number of epochs. We have defined the number of epochs as 120. And within this loop, we are calling the fit method of the regressor. So, for the short reminder, we have defined the regressor. This is the model action. Then we compiled this model, and this model class has a method fit. We pass as arguments the train set, X train. These are the input values. Y train, these are the output values. And then we have to say shuffle, false. Why? This is why because we're dealing with sequences and if we would shuffle, we would break the whole order of measurements, so it will not shuffle. Now, we have to define the number of epochs. And here, we have to set the epochs equal to one because we will call this fit method for all 120 epochs. And then we have to say batch size equals batch size. Batch size, in our case, 64. And then also very important, we say, reset states. So if the training is finished for an epoch, we need to reset all states which are the hidden state and cell state. We would not do this. We would take the states to the next epoch, but we don't want this. We want to start a new epoch freshly. We want to initialize the states with a zeroth. I will not call this method because I have already trained the model and it would take some minutes but we don't need this. I have stored the model on the system here and I can see where it's stored. I can call exclamation mark and then I immediately have accessed one line bash. And as I call this. I see, okay, I have a folder called Models, and in this folder, I have two models. One where I have used mean absolute error as a loss function and another one with a mean squared error. So, in the later sessions, we will see what is the difference in the prediction accuracy between those two. And Keras provides the method, load model. With this method, I can load the stored model, which I will do now. It will take some seconds and we see the model is loaded now. So, stay tuned. See you next time. Enjoy. Bye bye.
The initial lectures series on this topic can find in the below links: Introduction to Anomaly Detection https://www.youtube.com/watch?v=IFHX4HUAo1w&list=PLpW3QouFxOnM6YWVOrcUBaQiy8EWi05pi&index=37
How to implement an anomaly detector (1/2) https://www.youtube.com/watch?v=DN0H2Qz3Rxg How to implement an anomaly detector (2/2) https://www.youtube.com/watch?v=nYZuQg5K22Y How to deploy a real-time anomaly detector https://www.youtube.com/watch?v=LnPrT-IkzNw Introduction to Time Series Forecasting https://www.youtube.com/watch?v=G7_uNCOFEzE Stateful vs. Stateless LSTMs https://www.youtube.com/watch?v=R7CwkhZYJdU Batch Size! Which batch size is to choose? https://www.youtube.com/watch?v=wfyErdPsZPI Number of Time Steps, Epochs, Training, and Validation https://www.youtube.com/watch?v=tsprdX9RkRg Batch size and Training Set Size https://www.youtube.com/watch?v=5kLLKhNJlEY Input and Output Data Construction https://www.youtube.com/watch?v=zCHrQRlu688 Designing the LSTM network in Keras https://www.youtube.com/watch?v=Y3ApYArvBr8 Anatomy of an LSTM Node https://www.youtube.com/watch?v=WrA3LlKAbf0 Number of Parameters: How LSTM Parmeter Num is Computed. https://www.youtube.com/watch?v=oXNBR0U1A54 ... https://www.youtube.com/watch?v=jKjm1cX-mtM
13004421 Bytes