This project aims to create a sign language translator using computer vision and machine learning. It uses the Sign Language MNIST dataset to train a model that predicts hand gestures representing letters in American Sign Language (ASL). The project consists of several Python files, each handling different aspects of data preprocessing, model training, evaluation, and prediction.
Sign-Language-Translator/
├── data/
│ ├── sign_mnist_train.csv
│ └── sign_mnist_test.csv
├── saved_models/
│ └── sign_language_model.pth
├── src/
│ ├── preprocess.py
│ ├── model.py
│ ├── train.py
│ ├── evaluate.py
│ └── predict.py
└── main.py
-
Install Dependencies: Make sure all required libraries are installed using
pip
:pip install -r requirements.txt
-
Train the Model: Run the following command to start training:
python main.py --mode train --train_path "data/sign_mnist_train.csv" --test_path "data/sign_mnist_test.csv" --model_path "saved_models/sign_language_model.pth"
-
Evaluate the Model: After training, evaluate the model's performance:
python main.py --mode evaluate --test_path "data/sign_mnist_test.csv" --model_path "saved_models/sign_language_model.pth"
-
Make Predictions: To predict a specific image's label, run:
python main.py --mode predict --test_path "data/sign_mnist_test.csv" --model_path "saved_models/sign_language_model.pth" --image_index 5
The main entry point for running the project. It manages different operations like training, evaluation, and prediction based on the mode specified via command-line arguments.
main()
: The main method that takes command-line arguments and calls the respective functionality (train, evaluate, or predict) based on the chosen mode.
- You can customize the
--mode
argument to select the operation (train
,evaluate
, orpredict
). - Modify the
--train_path
and--test_path
if you want to specify different datasets. - Customize the
--model_path
to set a different location to save or load the model.
-
Training:
python main.py --mode train --train_path "data/sign_mnist_train.csv" --test_path "data/sign_mnist_test.csv" --model_path "saved_models/sign_language_model.pth"
-
Evaluation:
python main.py --mode evaluate --test_path "data/sign_mnist_test.csv" --model_path "saved_models/sign_language_model.pth"
-
Prediction:
python main.py --mode predict --test_path "data/sign_mnist_test.csv" --model_path "saved_models/sign_language_model.pth" --image_index 5
This file is responsible for loading and preprocessing the dataset. It reads the CSV files, scales the pixel values, and reshapes the data to be used by the model.
load_and_preprocess_data(train_path=None, test_path=None)
: Loads and preprocesses the training and test data. The function will return the images and labels in the required format.- train_path: Path to the training dataset CSV file (used for training).
- test_path: Path to the test dataset CSV file (used for evaluation/prediction).
- Returns: Preprocessed training, validation, and test data.
- You can change the
train_path
andtest_path
if your data is located elsewhere. - If you want to use a different dataset format, modify the file parsing logic inside this function.
This file defines the Convolutional Neural Network (CNN) model architecture. The model consists of convolutional layers followed by fully connected layers to classify hand gestures.
CNN
: Defines the CNN architecture, including convolution, pooling, and fully connected layers.
- You can modify the number of layers or their parameters (e.g., kernel size, number of filters) in the
CNN
class to adjust the model complexity. - Change the activation functions if needed (currently, ReLU is used).
This file contains the code for training the model. It defines the loss function, optimizer, and the training loop.
train_model(train_path, test_path, model_path)
: Trains the model on the training data and evaluates it on the test data. The trained model is then saved tomodel_path
.- train_path: Path to the training dataset.
- test_path: Path to the test dataset.
- model_path: Path to save the trained model.
- Change the batch size or learning rate in the
train_model
function. - You can also modify the number of epochs for training.
This file is responsible for evaluating the trained model on the test dataset. It calculates accuracy and other performance metrics.
evaluate_model(model_path, test_path)
: Loads the trained model frommodel_path
, evaluates it on the test dataset, and prints the accuracy.- model_path: Path to the trained model.
- test_path: Path to the test dataset.
- Modify the evaluation metrics (e.g., precision, recall) based on your requirements.
This file handles the task of predicting a hand gesture for a given test image. It takes an image and predicts the corresponding label.
make_prediction(model_path, test_image, test_label)
: Loads the model and predicts the label for the provided image.- model_path: Path to the trained model.
- test_image: The image to be predicted.
- test_label: The true label of the image.
- You can adjust the
image_index
to predict different images. - Modify the input format if you use a custom image format.