Giter Club home page Giter Club logo

digit-recogniser-machine-learning-tensorflow-javascript's Introduction

Digit Recogniser Machine Learning Tensorflow Javascript And React

This project is a simple implemntation of digit recongition using tensorflow js.

If you want to to have sample data, you can use kaggle website.

Demo Link: Here

Functions and Steps

In this readme, I try to explain what is happening in src/App.js.

_readTrainingData

First we need to download all the data from train.csv to our project and use papaparse for parsing the CSV to array. This data includes number of pixels with their information.

// Downloading 70 MB file
Papa.parse('/train.csv', {
    download: true,
    complete: async (results) => {
        // using result
    }
})

_initializingTheModel

After downloading the information, we need to define our model which is a sequential model and we want to use SGD, but for using SGD, we need a loss function and layers of model plus an optimizer.


Stochastic Gradient Descent (SGD) is a simple yet very efficient approach to discriminative learning of linear classifiers under convex loss functions such as (linear) Support Vector Machines and Logistic Regression. Even though SGD has been around in the machine learning community for a long time, it has received a considerable amount of attention just recently in the context of large-scale learning.


this.minstModel = tf.sequential();

this.minstModel.add(tf.layers.conv2d({
    inputShape: [28, 28, 1],
    kernelSize: 5,
    filters: 8,
    strides: 1,
    activation: 'relu',
    kernelInitializer: 'varianceScaling'
}));
this.minstModel.add(tf.layers.maxPooling2d({
    poolSize: [2, 2],
    strides: [2, 2]
}));
this.minstModel.add(tf.layers.conv2d({
    kernelSize: 5,
    filters: 16,
    strides: 1,
    activation: 'relu',
    kernelInitializer: 'varianceScaling'
}));
this.minstModel.add(tf.layers.maxPooling2d({
    poolSize: [2, 2],
    strides: [2, 2]
}));
this.minstModel.add(tf.layers.flatten());
this.minstModel.add(tf.layers.dense({
    units: 10,
    kernelInitializer: 'varianceScaling',
    activation: 'softmax'
}));

const LEARNING_RATE = 0.0001;
const optimizer = tf.train.sgd(LEARNING_RATE);
this.minstModel.compile({
    optimizer: optimizer,
    loss: 'categoricalCrossentropy',
    metrics: ['accuracy'],
});

If your question is how can we develop this model with their layers to be efficient, I should say there is a competition here Kaggle Digit Recognition The model above, it is what I found on internet plus a little change!

_trainNewModel

After initializing the model, you can use this function for start the training, because the training data is so big, we have to use part of the file each time to train the model

const history = await this.minstModel.fit(
batch.inputs, 
batch.labels, 
{
    batchSize: batchSize
});

_minscPredictionLabeled

And finally for evaluating our model, I didn't use the 100 inputs of training data and I developed to use it for knowing the accuracy or our model.

const output = this.minstModel.predict(evalData.inputs);

digit-recogniser-machine-learning-tensorflow-javascript's People

Contributors

ehsangazar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

nandhakishore11

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.