How to create model checkpoints in keras?

This recipe helps you create model checkpoints in keras

Recipe Objective

Create model checkpoints in keras. Sometimes deep learning models are very big and tedious to train, it requires a lot of hours, on a very big and research level sometimes days. If the running stops in between then we can loose a lot of time and work then you have to start from starting again. The checkpoints can be used directly, or used as the starting point for a new run, picking up where it left off. When we train the deep learning model, the checkpoints is the weights of the model.These weights are then used in making predictions, or it can be used as the basis for ongoing training.

Get Access to Plant Species Identification Project using Machine Learning

Step 1- Importing Libraries

#importing Libraries import pandas as pd import numpy as np from keras.datasets import mnist from sklearn.model_selection import train_test_split from keras.models import Sequential from keras.layers import Dense from keras.layers import Dropout from tensorflow.keras import layers #We will import the modelcheckpoint here from keras.callbacks import ModelCheckpoint

Step 2- Load the dataset

#Loading Dataset (X_train, y_train), (X_test, y_test) = mnist.load_data()

Step 3- Define the model.

We will define the model with the defining parameters.

#Model model = Sequential() model.add(layers.Dense(64, kernel_initializer='uniform', input_shape=(10,)))

Step 4- Defining the activation function.

We will Defining the activation function as ReLU.

model.add(layers.Activation('relu'))

Step 5- Adding layers

We will add layers to our model.

#Adding Layers model.add(Dense(512)) model.add(Dropout(0.2)) model.add(Dense(256, activation='relu')) model.add(Dropout(0.1))

Step 6- Creating Checkpoints

we will create our required checkpoint here after making layers.

#We will create the checkpoint. filepath="mnist_data_checkpoint" checkpoint = ModelCheckpoint(filepath, monitor='val_accuracy', verbose=1, save_best_only=True, mode='max') callbacks_list = [checkpoint] print(model) print(callbacks_list)

[]

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.

Hands-On Approach to Master PyTorch Tensors with Examples
In this deep learning project, you will learn how to perform various operations on the building block of PyTorch : Tensors.

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

Deep Learning Project for Time Series Forecasting in Python
Deep Learning for Time Series Forecasting in Python -A Hands-On Approach to Build Deep Learning Models (MLP, CNN, LSTM, and a Hybrid Model CNN-LSTM) on Time Series Data.

Recommender System Machine Learning Project for Beginners-1
Recommender System Machine Learning Project for Beginners - Learn how to design, implement and train a rule-based recommender system in Python

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

Azure Text Analytics for Medical Search Engine Deployment
Microsoft Azure Project - Use Azure text analytics cognitive service to deploy a machine learning model into Azure Databricks

Build Piecewise and Spline Regression Models in Python
In this Regression Project, you will learn how to build a piecewise and spline regression model from scratch in Python to predict the points scored by a sports team.

Locality Sensitive Hashing Python Code for Look-Alike Modelling
In this deep learning project, you will find similar images (lookalikes) using deep learning and locality sensitive hashing to find customers who are most likely to click on an ad.