A convolutional neural network built from scratch to classify handwritten digits (0–9), submitted to the Kaggle Digit Recognizer competition.
Competition accuracy: 98.685%
The model is trained on the MNIST-based Kaggle dataset of 28×28 grayscale images of handwritten digits. The goal is to correctly identify the digit in each image.
This project covers the full pipeline from data loading and visualization, through model architecture design and hyperparameter tuning, to generating a competition submission file.
The project has been completed in 2022.
Built using the Keras Sequential API with the following layers:
| Layer | Details |
|---|---|
| Rescaling | Normalizes pixel values to [0, 1] |
| Reshape | Converts flat input to 2D image (28×28×1) |
| Conv2D × 2 | Feature extraction |
| MaxPooling2D | Spatial downsampling |
| Conv2D × 2 | Deeper feature extraction |
| MaxPooling2D | Further downsampling |
| Flatten | Converts 2D feature maps to 1D vector |
| Dense | Fully connected layer |
| Dropout | Regularization to reduce overfitting |
| Dense (10 nodes) | Output layer — one node per digit class |
- Total parameters: 403,938 (all trainable)
- Loss function: Sparse Categorical Cross-Entropy
- Optimizer: Adam
- Callbacks: Learning rate scheduler, model checkpoint
| Set | Accuracy |
|---|---|
| Validation (15% holdout) | ~99% |
| Kaggle competition test set | 98.685% |
digit-recognizer-cnn/
│
├── digit_recognizer.ipynb # Full pipeline notebook
├── requirements.txt # Dependencies
└── README.md
Note: The dataset is not included in this repo. It can be downloaded directly via the Kaggle API as shown in the notebook.
- Clone the repository:
git clone https://github.com/MostafaJahanian/digit-recognizer-cnn.git
cd digit-recognizer-cnn- Install dependencies:
pip install -r requirements.txt- Set up Kaggle API credentials (
kaggle.json) and run the notebook top to bottom.
The notebook was developed in Google Colab. The data loading cells use the Kaggle API and Colab file upload — adjust these if running locally.
See requirements.txt. Main libraries: TensorFlow, Keras, Pandas, NumPy, Matplotlib, Seaborn, Scikit-learn.