Git Product home page Git Product logo

pytorch-based-mnist-digit-prediction's Introduction

Pytorch based Digit prediction using MNIST Dataset

The model is made using Pytorch and the dataset used is MNIST dataset. The MNIST dataset is an acronym that stands for the Modified National Institute of Standards and Technology dataset. It is a dataset of 60,000 small square 28ร—28 pixel grayscale images of handwritten single digits between 0 and 9.

The mean value and deviation in MNIST dataset are 0.1307 and 0.3081.

The Flask API

I have used flask framework to make the API, which takes the image and predict the digit class.

POST: http://127.0.0.1:5000/predict/
body: 
{
    "file": <image_file>
}

I have added validation on the format of the input images, only (.png, .jpg, .jpeg) format are accepted. The response of the request will look like this:

{
  "class_name": "7",
  "prediction": 7
}

I have created the two layer neural network for training the model. Two Linear layers, and one activation function used here us ReLU. As this problem is the multiclass classification problem, I've used CrossEntropyLoss() to find out the loss, then we don't need to add one more layer at the end i.e. Softmax Layer.

The transformers used in this project are, Grayscale(num_output_channels=1), Normalize((0.1307,), (0.3081,)), ToTensor(), Resize((28, 28)).

We first convert the request image into Image Bytes using BytesIO, then we pass the image_bytes to all the transformers mentioned above. Then we first resize the image_tensor to (-1, 28*28), then pass the transformed Tensor to the pre-trained model, which will return the digit class, and the prediction in JSON format through the API response.

Then for visualizing the data, I've used tensorboard to show the metrics, graphs, images etc.

pytorch-based-mnist-digit-prediction's People

Contributors

mohit-15 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.