Search⌘ K
AI Features

DL Model Training, Testing, and Evaluation

Explore how to create deep learning models using the Keras Sequential class. Learn to configure models with optimizers and loss functions, train using datasets, and evaluate performance with test data. Understand how to apply these steps to prepare models for deployment in Android applications.

Keras API allows us to build DL models using the Sequential model class, functional interface, and model subclassing. Let’s design a Sequential Keras model, perform model training, and test/evaluate the trained model.

Model creation

The Sequential model class can create a DL model with layers stacked one after the other. For instance, the following code imports the Sequential model and builds a simple CNN architecture:

Python 3.8
import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Input, Conv2D, MaxPool2D, Flatten, Dense
my_model = Sequential([
Input(shape=(28,28,1)),
Conv2D(filters=10, kernel_size=(7,7), padding="same", activation="relu"),
MaxPool2D(pool_size=(2,2)),
Conv2D(filters=16, kernel_size=(7,7), padding="same", activation="relu"),
MaxPool2D(pool_size=(2, 2)),
Flatten(),
Dense(units=100, activation="relu"),
Dense(units=10, activation="softmax")
])
print (my_model.summary())
  • Line 5: We use the Sequential ...