Saving and loading a model
Training a neural network is hard work and time-consuming. That's why retraining a model every time is impractical. The good news is that we can save a network to disk and load it whenever we need it, whether to improve its performance with more training or to use it to make predictions on fresh data. In this recipe, we'll learn about different ways to persist a model.
Let's get started!
How to do it…
In this recipe, we'll train a CNN on mnist
just to illustrate our point. Let's get started:
- Import everything we will need:
import json import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import LabelBinarizer from tensorflow.keras import Model from tensorflow.keras.datasets import mnist from tensorflow.keras.layers import BatchNormalization from tensorflow.keras.layers import Conv2D from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Dropout...