### How to save and load keras model ?

The easiest way to save and load keras model is:

#### Save model

1 |
model.save('/user/path-to-dir/saved-model.h5') |

#### Load model

1 2 |
from keras.models import load_model new_model = load_model('/user/path-to-dir/saved-model.h5') |

This technique of saving the model is very useful. This approach saves:

- Architecture of the model
- Weights of the model
- Training state (like loss, optimizer etc.)
- State of the optimizer, which helps to train from where you left.

Another approach is by saving weights:

Save weights

1 |
model.save_weights('model_weights.h5') |

1 |
model.load_weights('model_weights.h5') |

To load weights, you need to first build the model and then load weights.

Final approach is to save the architecture of the model.

1 2 |
#save architecture model.to_json() |

1 2 3 |
#then load from keras.models import model_from_json model = model_from_json(json_string) |