Sign Language Recognition System using TensorFlow in Python
Last Updated :
09 Apr, 2025
Sign language is a important mode of communication for individuals with hearing impairments. Building an automated system to recognize sign language can significantly improve accessibility and inclusivity.
In this article we will develop a Sign Language Recognition System using TensorFlow and Convolutional Neural Networks (CNNs) .
Step 1: Importing Libraries
In the first step we will import all the necessary libraries. Python libraries simplify data handling and machine learning tasks.
Python
import string
import pandas as pd
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from tensorflow.keras.preprocessing.image import ImageDataGenerator
Step 2: Load the Dataset
The dataset is available as two CSV files, sign_mnist_train.csv and sign_mnist_test.csv. Each row in the CSV file is a training sample with the 0th index having the labels from 0-25 and the rest of the row containing the 784-pixel values of a 28 x 28 image. Each pixel value will be in the range [0, 255].
You can download the dataset from here.
Python
df = pd.read_csv('/content/sign_mnist_train.csv')
df.head()
Output:

First five rows of the dataset
Step 3: Data Preprocessing
The dataset has been provided in two files one is for training and the other one is for testing. We will load this data and then one hot encode the labels considering the fact we are not building the classifier for ‘J’ and ‘Z’ alphabet.
- load_data(path): loads and processes the dataset. It reshapes the image data into 28×28 and applies one-hot encoding to the labels.
Python
def load_data(path):
df = pd.read_csv('/content/sign_mnist_train.csv')
y = np.array([label if label < 9
else label-1 for label in df['label']])
df = df.drop('label', axis=1)
x = np.array([df.iloc[i].to_numpy().reshape((28, 28))
for i in range(len(df))]).astype(float)
x = np.expand_dims(x, axis=3)
y = pd.get_dummies(y).values
return x, y
X_train, Y_train = load_data('/content/sign_mnist_train.csv')
X_test, Y_test = load_data('/content/sign_mnist_test.csv')
X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size=0.2, random_state=42)
Now let’s check the shape of the training and the testing data.
Python
print(X_train.shape, Y_train.shape)
print(X_test.shape, Y_test.shape)
Output:
(21964, 28, 28, 1) (21964, 24)
(27455 28, 28, 1) (27455, 24)
Step 4: Data Visualization
In this section, we will try to visualize images for signs of some of the alphabets which have been provided to us to build the classifier for each class.
Python
class_names = list(string.ascii_lowercase[:26].replace(
'j', '').replace('z', ''))
plt.figure(figsize=(10, 10))
for i in range(10):
plt.subplot(5, 5, i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(X_train[i].squeeze(), cmap=plt.cm.binary)
plt.xlabel(class_names[np.argmax(Y_train, axis=1)[i]])
plt.tight_layout()
plt.show()
Output:

Visualized images of the signs corresponding to various alphabet classes.
Step 5: Model Development
From this step onward, we use TensorFlow to build our CNN model. The Keras framework of TensorFlow provides all the functionalities needed to define the architecture of a Convolutional Neural Network and train it on the data.
We will implement a sequential model containing the following parts:
- Three Convolutional Layers followed by MaxPooling layers.
- Flatten Layer to flatten the output of the convolutional layers.
- Fully Connected Layers followed by the output layer.
- BatchNormalization Layers to enable stable and fast training.
- Dropout Layer to avoid overfitting.
The final output layer will have 24 units corresponding to the 24 alphabet classes.
Python
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(filters=32,
kernel_size=(3, 3),
activation='relu',
input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(filters=64,
kernel_size=(3, 3),
activation='relu'),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Flatten(),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Dense(256, activation='relu'),
tf.keras.layers.Dropout(0.3),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Dense(24, activation='softmax')
])
model.summary()
Output:

When compiling the model, we provide three essential parameters:
- Optimizer: The method used to optimize the cost function (e.g., gradient descent).
- Loss Function: The function used to evaluate the model’s performance.
- Metrics: Metrics used to evaluate the model during training and testing.
Python
model.compile(
optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy']
)
Now we will train the model using the training data and validate it using the validation data, utilizing model.fit() function.
Python
history = model.fit(
X_train, Y_train,
validation_data=(X_val, Y_val), epochs=10, batch_size=32, verbose=1)
Output:

Step 6: Model Evaluation
After training the model, we will visualize the training and validation accuracy as well as the loss for each epoch. This helps us analyze how well the model is performing.
Python
history_df = pd.DataFrame(history.history)
history_df.loc[:,['loss','val_loss']].plot()
history_df.loc[:,['accuracy','val_accuracy']].plot()
plt.show()
Output:


The training loss keeps decreasing which means the model is learning well. However, the validation loss is fluctuating a little suggesting the model might be overfitting slightly. The training accuracy is very high, close to 100% while validation accuracy also improves but is slightly lower. This means the model performs well on training data but may need fine-tuning to improve generalization.
Finally, let’s evaluate the performance of the model on the test dataset using model.evaluate() function.
Python
loss, accuracy = model.evaluate(X_test, Y_test, verbose=1)
print(f'Test Accuracy: {accuracy * 100:.2f}%')
Output:

The model achieves 99% accuracy on the test set, which is impressive for a simple CNN model.
By using just a simple CNN model we are able to achieve an accuracy of 99% which is really great. This shows that this technology is certainly going to help us build some amazing applications which can be proved a really great tool for people with some special needs.
Similar Reads
Image Recognition using TensorFlow
In this article, we'll create an image recognition model using TensorFlow and Keras. TensorFlow is a robust deep learning framework, and Keras is a high-level API(Application Programming Interface) that provides a modular, easy-to-use, and organized interface to solve real-life deep learning problem
6 min read
Traffic Signs Recognition using CNN and Keras in Python
We always come across incidents of accidents where drivers' Overspeed or lack of vision leads to major accidents. In winter, the risk of road accidents has a 40-50% increase because of the traffic signs' lack of visibility. So here in this article, we will be implementing Traffic Sign recognition us
6 min read
Skin Cancer Detection using TensorFlow
In this article, we will learn how to implement a Skin Cancer Detection model using Tensorflow. We will use a dataset that contains images for the two categories that are malignant or benign. We will use the transfer learning technique to achieve better results in less amount of training. We will us
5 min read
Single Layer Perceptron in TensorFlow
Single Layer Perceptron is inspired by biological neurons and their ability to process information. To understand the SLP we first need to break down the workings of a single artificial neuron which is the fundamental building block of neural networks. An artificial neuron is a simplified computatio
4 min read
Detecting Spam Emails Using Tensorflow in Python
Spam messages are unsolicited or unwanted emails/messages sent in bulk to users. Detecting spam emails automatically helps prevent unnecessary clutter in users' inboxes. In this article, we will build a spam email detection model that classifies emails as Spam or Ham (Not Spam) using TensorFlow, one
5 min read
Automatic Number Plate Recognition System using EasyOCR
Automatic License/Number Plate Recognition (ANPR) is the process of detecting position of number plate and then using Optical Character Recognition technique to identify the text on the plate from a image or video. It is widely used in video surveillance and for security purposes. In this article, w
6 min read
One Hot Encoding using Tensorflow
In this post, we will be seeing how to initialize a vector in TensorFlow with all zeros or ones. The function you will be calling is tf.ones(). To initialize with zeros you could use tf.zeros() instead. These functions take in a shape and return an array full of zeros and ones accordingly. Code: imp
2 min read
Object Detection using TensorFlow
Identifying and detecting objects within images or videos is a key task in computer vision. It is critical in a variety of applications, ranging from autonomous vehicles and surveillance systems to augmented reality and medical imaging. TensorFlow, a Google open-source machine learning framework, pr
7 min read
Python | Multiple Face Recognition using dlib
This article aims to quickly build a Python face recognition program to easily train multiple images per person and get started with recognizing known faces in an image. In this article, the code uses ageitgey's face_recognition API for Python. This API is built using dlib's face recognition algorit
4 min read
Predict Fuel Efficiency Using Tensorflow in Python
Predicting fuel efficiency is a important task in automotive design and environmental sustainability. In this article we will build a fuel efficiency prediction model using TensorFlow one of the most popular deep learning libraries. We will use the Auto MPG dataset which contains features like engin
5 min read