Skip to content

abu14/digit-recognition-with-neural-networks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Handwritten Digit Recognition with Convolutional Neural Networks

GitHub contributors GitHub forks GitHub stars GitHub issues GitHub license LinkedIn

Digit Recognition

This is recognizing handwritten digits from the MNIST dataset using CNNs with 99.3 Accuracy Score. For an evern closer look on the steps taken please refer to the notebook.

Project Structure

mnist-digit-recognition
├── data_loader.py       
├── data_preprocess.py  
├── model.py           
├── train.py            
├── predict.py      
└── main.py           

Tools Used

Getting Started

  1. Clone the Repository:

    git clone https://github.com/abu14/Digit-Recognition-CNN-99.3-Score.git  
    cd Digit-Recognition-CNN-99.3-Score  
  2. Install Dependencies:

    pip install -r requirements.txt

    Dependencies

    numpy
    pandas
    tensorflow
    scikit-learn
    
  3. Download the Data:

    The MNIST dataset is available on Kaggle (Digit Recognizer competition). You can download the train.csv, test.csv, and sample_submission.csv files. But I've placed them in the directory named data inside the project's root folder for your convenience.

  4. Run the Main Script:

    python main.py

    This will:

    • Load the data.
    • Preprocess the data.
    • Create and train the CNN model.
    • Evaluate the model's performance.
    • Make predictions on the test data.
    • Create a submission.csv file containing the predictions.

Usage

The main.py script orchestrates the entire process. Here's a breakdown of how they can be used individually:

  1. Data Loading:

    from data_loader import load_data
    
    train_data, test_data, submission_data = load_data("data/train.csv", "data/test.csv", "data/sample_submission.csv")
  2. Data Preprocessing:

    from data_preprocess import preprocess_data
    
    x_train, x_val, y_train, y_val, x_test = preprocess_data(train_data, test_data) #If you want to preprocess the test data too
    x_train, x_val, y_train, y_val = preprocess_data(train_data) #If you only want to preprocess the train data
  3. Model Creation:

    from model import create_model
    
    model = create_model()
  4. Model Training:

    from train import train_model
    
    history = train_model(model, x_train, y_train, x_val, y_val, epochs=40, batch_size=32)  # Adjust epochs and batch size as needed
  5. Prediction:

    from predict import predict, create_submission_file
    
    predicted_labels = predict(model, x_test)
    create_submission_file(predicted_labels, submission_data)

Model Architecture

The CNN model architecture consists of:

  • Convolutional layers with ReLU activation.
  • Batch normalization layers.
  • Max pooling layers.
  • Dropout layers for regularization.
  • Fully connected (dense) layers.
  • A softmax output layer for classification.

Training

  • Optimizer: Adam optimizer.
  • Loss Function: Categorical cross-entropy.
  • Data Augmentation: ImageDataGenerator is used for real-time data augmentation during training.
  • Learning Rate Scheduling: LearningRateScheduler is used to adjust the learning rate during training.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues. I respond on all of my socials so feel free to reach out.

License

This project is licensed under the MIT License. See LICENSE file for more details.

Contact

Abenezer Tesfaye

⭐️ Email - tesfayeabenezer64@gmail.com

Project Link: Github Repo

About

Recognizing hand written digits with the use of neural networks end to end project.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published