· Deep Learning · 2 min read
📋 Prerequisites
- Basic Python knowledge
- Familiarity with Jupyter or any Python environment
🎯 What You'll Learn
- Build and train your first neural network
- Understand the workflow of deep learning projects
- Evaluate model accuracy on test data
- Gain confidence to explore more projects
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! 🚀