Course Content
Your First Deep Learning Model
Build and train your first complete neural network
Introduction
In this tutorial, you will build your first deep learning model to classify handwritten digits using the MNIST dataset with TensorFlow and Keras.
What is MNIST?
MNIST is a dataset of 28x28 grayscale images of handwritten digits (0-9), commonly used for getting started with image classification.
Step-by-Step Guide
1οΈβ£ Install Required Libraries
If you donβt have TensorFlow installed:
pip install tensorflow
2οΈβ£ Import Libraries
import tensorflow as tf
from tensorflow.keras import layers, models
3οΈβ£ Load and Prepare the Dataset
# Load dataset
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# Normalize pixel values
x_train, x_test = x_train / 255.0, x_test / 255.0
4οΈβ£ Build Your First Neural Network
model = models.Sequential([
layers.Flatten(input_shape=(28, 28)),
layers.Dense(128, activation='relu'),
layers.Dropout(0.2),
layers.Dense(10, activation='softmax')
])
5οΈβ£ Compile the Model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
6οΈβ£ Train the Model
model.fit(x_train, y_train, epochs=5, validation_split=0.1)
7οΈβ£ Evaluate on Test Data
test_loss, test_acc = model.evaluate(x_test, y_test, verbose=2)
print(f"Test accuracy: {test_acc}")
Summary
β
You built and trained your first deep learning model using Keras.
β
You learned how to preprocess data, build, compile, train, and evaluate a neural network.
β
You can now confidently experiment with different datasets and models.
Whatβs Next?
β
Try adjusting the number of layers and neurons to see the impact on accuracy.
β
Experiment with different activation functions and optimizers.
β
Move on to Convolutional Neural Networks (CNNs) for improved image classification.
Join our SuperML Community to share your first project, get feedback, and continue your deep learning journey.
Happy Building! π