Code Monkey home page Code Monkey logo

handwritten-digits-recognition-pytorch's Introduction

HandwrittenDigitsRecognition-PyTorch

A basic handwritten-digits recognition project based on PyTorch using datasets from MNIST

Data resource: MNIST

Referenced code:

Sincerely express my gratitude to the authors above. If this repository infringed anyone's copyright, please let me know so that I will delete and apologize at once. Thank you!

Brief Introduction

This project trained a shallow neural network model using PyTorch. It has some basic functions, including "output the test result", "print the accuracy graph", "add noise to the source image", etc.

You can customize the parameters of the model, such as the number of epochs, nodes, layers, batch_size and learning_rate. The hyperparameters used in this project are learned from the referenced code linked above.

Dependencies

torch | numpy | matplotlib

Python Files Explanation

check_device.py: If your device support CUDA, it will print out "cuda", otherwise it will print out "cpu". You can add CUDA integration to this project to improve the speed. By default, this project is based on CPU.

check_datasets.py: Show 25 random images from the datasets. You can change the number if you want.

model_training.py: Build the training model. A trained model has already been included in the repository, but you can rebuild it if you want. The resource datasets are in the "data" folder. After execution, you will get a trained model (trainedModel.pth), a record of loss by batch (loss_rec.csv) and a record of loss by epoch (loss_rec_epoch.csv).

noiseless_testing.py: Test the model using the test_data without noise. It will show the output result and accuracy, and you will get a record of the accuracy (accuracy_noiseless.csv).

noise_added_testing.py: Test the model using the test_data with Gaussian noise added. You can change the level of the noise by editing the "noise_level". It will show the accuracy of each level of the noise, and you will get a record of it (accuracy_noise_added.csv & noise_level.csv)

figure_display.py: Print the graphs from the data generated above. fig1: Loss (by batch), fig2: Loss (by epoch), fig3: noiseless_accuracy, fig4: noise_added_accuracy.

custom_testing.py: Test the handwritten digits created by yourself to see the result (put the images in the "test" folder).

Problems to Be Solved

  • 1. The value of the tensor will exceed [0,1] after adding the Gaussian noise, which can cause some unwanted influence. (Use torch.clamp() to solve it)
  • 2. The accuracy of "custom test" is worse than the accuracy of the MNIST test datasets, why? (Solved after the 1. was solved)
  • 3. Unwanted zeros appear in the "noise_level.csv" and "accuracy_noise_added.csv" when the noise_level set above 0.58. Bug?

If you have any questions, please feel free to ask me, it's my pleasure to help.

Thanks for reading!

handwritten-digits-recognition-pytorch's People

Contributors

zenpk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.