This is a Python 3.11 project which implements digit recognition using a Convolutional Neural Network (CNN). The dataset utilized is MNIST. It contains handwritten digit images for training and validating the model's digit classification capabilities.
├── data/MNIST/raw
│ └── handwritten images used for training and testing.
│
├── frontend/digit_recog_frontend
│ └── frontend implementation of the model. It is a react projecct.
│ See the README file in this folder for details.
│
├── export.py (Converts a trained PyTorch model into an ONNX model.)
│
├── Main.ipynb (The Jupyter Notebook code. The model was firstly written in Jupyter,
│ then converted into python code. It is equivalent to main.py.)
│
├── main.py (Contains the implementation of the CNN, the training, and the testing. )
│
├── model.py (The ONNX model generated by export.py.)
│
└── model_weights.pth (Trained PyTorch model params will be saved as model_weights.pth.)
- torch
- torchvision
- numpy
You can install the required dependencies using the following command
pip install torch torchvision numpy- Install Dependencies: Ensure that you have installed the required dependencies.
- Run the Code<\b>: Execute the main.py file in the project's root directory.
- Save Model<\b>: The result parameters of the model in the training will be saved in model_weights.pth. Run the export.py file to export the model as onnx.
The project utilizes a simple Convolutional Neural Network named CNN in main.py.
class CNN(nn.module):
# ...(Model architecture)The training and testing functions are defined in main.py after the definition of the CNN model
def train(epoch):
#... (Training function)
def test():
#... (Testing function)The accuracy rate of running the test image dataset is around 98%.
However, it demonstrates difficulty in distinguishing 7 and 1 in real testing.