LeNet-5, a pioneering convolutional neural network (CNN) developed by Yann LeCun and his team in the 1990s, was a game-changer in computer vision and deep learning. This groundbreaking architecture was explicitly crafted to revolutionize the recognition of handwritten and machine-printed characters. Unlike traditional methods, LeNet-5 introduced a novel approach that eliminated the need for manual feature engineering, directly processing pixel images through convolutional layers, subsampling, and fully connected layers. Its success extended beyond character recognition, serving as a cornerstone for modern deep learning models and influencing subsequent architectures in computer vision, object recognition, and image classification.
Yann LeCun’s early application of backpropagation algorithms to practical problems laid the foundation for LeNet-5, designed to read handwritten characters and excelling in identifying zip code numbers provided by the US Postal Service. Its successive versions and applications, such as the ability to read millions of checks daily, triggered a surge of interest among researchers, shaping the landscape of neural networks and inspiring the evolution of deep learning.
The success of LeNet-5 and subsequent applications, such as systems capable of reading millions of checks per day, sparked widespread interest among researchers in neural networks. While today’s top-performing neural network architectures have evolved beyond LeNet-5, its groundbreaking design, and accomplishments laid the foundation for numerous subsequent models, significantly shaping and inspiring deep learning. LeNet-5 remains a testament to innovation and an enduring symbol of the evolution of machine learning and image recognition.
This article was published as a part of the Data Science Blogathon.
LeNet, also known as LeNet-5, is a pioneering convolutional neural network (CNN) architecture developed by Yann LeCun and his team in the 1990s. It was designed explicitly for handwritten and machine-printed character recognition tasks.LeNet-5’s significance lies in its successful demonstration of hierarchical feature learning and its effectiveness in character recognition. Its impact extends beyond its original purpose, influencing the development of modern deep learning models and serving as a foundational architecture for subsequent advancements in computer vision, image recognition, and various machine learning applications.
LeNet-5 is a Convolutional Neural Network (CNN) with a specific architecture employed in character recognition tasks. It consists of multiple layers, excluding the input layer, containing trainable parameters. Notably, it processes 32×32-pixel images, more significant than the characters in its database, focusing on potentially distinctive features’ centering. Input pixel values are normalized for better learning efficiency.
LeNet’s architecture combines convolutional, subsampling, and fully connected layers with specific connectivity patterns. It uses normalization for input pixels and a series of layers to extract distinctive features from the data for efficient learning. Additionally, it implements unique strategies to prevent saturation of activation functions and uses specific loss functions for efficient training.
[Input: 28x28x1]
|
[Conv2D: 6 filters, 5x5, tanh]
|
[Average Pooling: 2x2, stride 2]
|
[Conv2D: 16 filters, 5x5, tanh]
|
[Average Pooling: 2x2, stride 2]
|
[Flatten]
|
[Dense: 120, tanh]
|
[Dense: 84, tanh]
|
[Dense: 10, softmax (output)]
Convolutional Layer 1:
Average Pooling Layer 1:
Convolutional Layer 2:
Average Pooling Layer 2:
Fully Connected Layers:
Start with the code to implement LeNet-5 in TensorFlow using the Keras API. It’s a good beginning to work with the MNIST dataset.
import tensorflow as tf
from tensorflow import keras
from keras.datasets import mnist
from keras.layers import Dense, Flatten, Conv2D, AveragePooling2D
from keras.models import Sequential
from tensorflow.keras.utils import plot_model
Load the MNIST dataset for training and testing images. This function loads the dataset, which consists of handwritten digit images and their respective labels. The data is divided into training and testing sets.
(X_train, y_train), (X_test,y_test) = mnist.load_data()
Output:
The reshape function in this context is adjusting the shape of the images to make them suitable for processing in a CNN. The shape (28, 28, 1) signifies that the images are 28×28 pixels and have a single channel (grayscale images). This transformation is necessary because most CNNs expect images to be in a specific shape, often represented as (width, height, channels).
#perfoming reshape
X_train = X_train.reshape(X_train.shape[0],28,28,1)
X_test = X_test.reshape(X_test.shape[0],28,28,1)
# Check the shape of data
X_train.shape
The code snippet you’ve provided normalizes the image pixel values in the training and testing datasets. Divining every pixel value by 255 ensures that the pixel values range from 0 to 1.
# Normalization ---> convert 0 to 1
X_train = X_train/255
X_test = X_test/255
The classes for the MNIST dataset are transformed into categorical data with 10 classes. Each label is converted into a vector where each element represents a class, with 1 in the index corresponding to the class and 0 elsewhere.
# One hot encoding
y_train = keras.utils.to_categorical(y_train,10)
y_test = keras.utils.to_categorical(y_test,10)
This code snippet demonstrates constructing the LeNet-5 model using the Keras Sequential API in TensorFlow. It defines the layers and their configurations and compiles the model with an optimizer, loss function, and metrics for evaluation.
model = Sequential()
# first layer
model.add(Conv2D(6, kernel_size=(5,5), padding="valid", activation="tanh", input_shape =(28,28,1)))
model.add(AveragePooling2D(pool_size=(2,2),strides=2, padding='valid'))
#second layer
model.add(Conv2D(16, kernel_size=(5,5), padding="valid", activation="tanh"))
model.add(AveragePooling2D(pool_size=(2,2),strides=2, padding='valid'))
# flatten layer
model.add(Flatten())
# ANN
model.add(Dense(120, activation='tanh'))
model.add(Dense(84, activation='tanh'))
model.add(Dense(10, activation='softmax'))
model.summary()
Output:
The “compile” method prepares the model for training by defining its optimization method, loss function, and the metrics to monitor.
model.compile(loss= keras.metrics.categorical_crossentropy, optimizer =keras.optimizers.Adam(),\
metrics= ['accuracy'])
Model training: The “fit ” function trains the model using the provided training data and validates it using the test data.
model.fit(X_train,y_train, batch_size=128,epochs=10 , verbose=1, validation_data=(X_test,y_test))
output:
The model “evaluate()” function is utilized to evaluate the model’s performance on a test dataset. The result provides the test loss and test accuracy.
score = model.evaluate(X_test,y_test)
print('Test loss', score[0])
print('Test Accuracy', score[1])
Visualization:
# Create a bar chart to visualize the comparison
import matplotlib.pyplot as plt
predicted_labels = np.argmax(predictions, axis=1)
# Compare predicted labels with true labels
correct_predictions = np.equal(predicted_labels, np.argmax(y_test, axis=1))
plt.figure(figsize=(12, 6))
plt.bar(range(len(y_test)), correct_predictions, \
color=['green' if c else 'red' for c in correct_predictions])
plt.title('Comparison of Predicted vs. True Labels')
plt.xlabel('Sample Index')
plt.ylabel('Correct Prediction (Green: Correct, Red: Incorrect)')
plt.show()
Output:
LeNet’s influence extends far beyond its original task. Its success paved the way for deeper exploration into convolutional neural networks (CNNs). Its efficient design and performance on digit recognition tasks set the stage for advancements in various computer vision applications, including image classification, object detection, and facial recognition.
The impact of LeNet extends to numerous real-world applications. From recognizing handwritten digits in postal services to revolutionizing healthcare by aiding in medical image analysis, the foundational concepts of LeNet have influenced a myriad of fields.
Researchers have developed more complex CNN architectures to overcome these limitations, incorporating sophisticated techniques to address these challenges while improving performance on various tasks.
LeNet, as an early convolutional neural network, is a pivotal milestone in deep learning. Its inception by Yann LeCun and the team marked a breakthrough, particularly in handwritten character recognition and image analysis. LeNet faces challenges adapting to modern complex tasks and diverse datasets due to architectural simplicity and potential overfitting. Its legacy remains vital, inspiring more advanced architectures and playing a crucial role in developing deep learning models.
LeNet’s inception marked a pivotal moment in the history of deep learning. Its success in image recognition tasks and the principles has set the stage for the evolution of modern convolutional neural networks. Its enduring legacy continues to shape the landscape of computer vision and artificial intelligence.
A: LeNet is a convolutional neural network (CNN) designed by Yann LeCun and his team in the 1990s. It was developed for handwritten character recognition and image analysis.
A: LeNet’s applications are optical character recognition, digit and letter recognition, and image classification tasks in healthcare and security systems.
A: LeNet was pivotal as one of the earliest successful applications of CNNs. It served as a cornerstone in developing neural networks for image recognition tasks.
A: LeNet’s success led to a wave of interest in neural networks, subsequent advancements in computer vision and deep learning. Its design principles and architecture influenced the development of many modern AI models.
A: LeNet’s architecture introduced the concept of hierarchical feature extraction through convolutional layers. Enabling effective pattern recognition, which became a standard in modern deep learning models.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.