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.
mnist-digit-recognition
├── data_loader.py
├── data_preprocess.py
├── model.py
├── train.py
├── predict.py
└── main.py
-
Clone the Repository:
git clone https://github.com/abu14/Digit-Recognition-CNN-99.3-Score.git cd Digit-Recognition-CNN-99.3-Score
-
Install Dependencies:
pip install -r requirements.txt
Dependencies
numpy pandas tensorflow scikit-learn
-
Download the Data:
The MNIST dataset is available on Kaggle (Digit Recognizer competition). You can download the
train.csv
,test.csv
, andsample_submission.csv
files. But I've placed them in the directory nameddata
inside the project's root folder for your convenience. -
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.
The main.py
script orchestrates the entire process. Here's a breakdown of how they can be used individually:
-
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")
-
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
-
Model Creation:
from model import create_model model = create_model()
-
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
-
Prediction:
from predict import predict, create_submission_file predicted_labels = predict(model, x_test) create_submission_file(predicted_labels, submission_data)
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.
- 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.
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.
This project is licensed under the MIT License. See LICENSE file for more details.
⭐️ Email - tesfayeabenezer64@gmail.com
Project Link: Github Repo