Introduction to Tensorflow
Tensorflow, an End-to-End Machine Learning Library from Google

Introduction to Tensorflow

Tensorflow is an Open-Source Machine Learning and Deep Learning Library that was launched by Google back in 2015 under Apache License 2.0. The popularity of Tensorflow has scaled heights ever since, with multiple companies and organization turning towards Tensorflow and the ecosystem it provides which is leveraged to bring the benefits of Machine Learning and Deep Learning in a much wider audience. The word "Tensorflow" is made up of two words: Tensor and Flow. Tensor is a multidimensional data array that is used for mathematical computations while the flow is a graph of operations that is performed on the multidimensional array.

No alt text provided for this image

Tensorflow and Models built with Tensorflow are one of the most trending Open-Source Projects on Github.

You might ask, why Tensorflow for Machine Learning and what makes it better than its competitors? Tensorflow provides multiple Application Programming Interfaces (APIs) with the low-level APIs rendering us a Programming Control upon Cores while the high-level APIs rendering us control over Tensorflow core. Tensorflow makes it very easy to develop and deploy Machine Learning Models and allow us to develop Machine Learning Applications using custom datasets or pre-trained models.

Tensorflow also provides a very flexible architecture and supports the production of Machine Learning Models on CPUs, GPUs and TPUs as well as Edge Devices. Tensorflow is supported by many Programming Languages and is highly popular in Python Programming Language including other Scripting Languages like Javascript and Swift. Tensorflow is used by multiple organizations all across the world like Airbus, PayPal, Twitter to name a few. Let us have a look at a simple "Hello World" code written in Tensorflow:

No alt text provided for this image

Since we are clear with Tensorflow and implementing a basic code with Tensorflow, let's move onto implementing a simple code to recognize Hand-Written Digits using Tensorflow and develop a model based on that.

Implementing MNIST Hand-Written Digit Recognition using Tensorflow

The MNIST database is a large database of handwritten digits that is commonly used for training various image processing systems. MNIST ("Modified National Institute of Standards and Technology") is the de facto “Hello World” dataset of computer vision. It is a dataset of 60,000 small square 28×28 pixel grayscale images of handwritten single digits between 0 and 9. In this Code, we will implement an MNIST Digit Recognition Application using Tensorflow which can recognize digits from 0-9.

No alt text provided for this image

Let us implement our code:

  1. At first, we will be importing the necessary modules and dependencies required to run our code. We will import Tensorflow and load the MNIST Dataset from Tensorflow which is available by Keras API. Once the Dataset has been loaded, we will normalize the data. MNIST Dataset comprises of Images in 32x32 pixels each for red, blue and green channels and has a value between 0-255. We will normalize the values to 0-1.
No alt text provided for this image

2. Next, we will implement our Tensorflow Model which at first consists of tf.keras.models.Sequential() function which creates a linear arrangement of layers. Next, we will add, tf.keras.layers.Flatten(input_shape=(28,28)) which will implement one node for each pixel in the image. Flatten creates 28*28=784 Nodes which can represent each pixel in an image. tf.keras.layers.Dense() will implement a densely connected layer. We will also be using Activation Functions here: ReLU and Softmax which takes logits as an input and convert them to activated values. A Dropout Layer tf.keras.layers.Dropout() is also added to counter the disadvantages of a Densely Connected Layer and simply means that some nodes will not be passing information to other nodes in next iteration. At last a model.compile() function is called which will run the model.

No alt text provided for this image

3. Lastly, we will run the model for 10 Epochs (You can change the number of epochs according to your needs) and we will use model.evaluate() function to compute the accuracy of our model.

No alt text provided for this image

We will get an accuracy of nearly 98% on the MNIST Dataset. The model can be saved later in a Keras Model File with a .h5 Extension which can be loaded onto other code which will cut down the time required for training and testing the model. The Code for the above-mentioned processing has been saved here.





Aman Kapoor

SDE @ Amazon | 5? CodeChef | Specialist Codeforces

4 年

Great article Harsh Bardhan Mishra

Pytorch >> tensorflow ( except tensorflow serving)

Harshvardhan Mamgai

Member Technical at ADP|Microsoft student partner 2020

4 年

Amazing tutorial

要查看或添加评论,请登录

Harsh Mishra的更多文章

  • Creating Dog versus Cat Classifier using Transfer Learning

    Creating Dog versus Cat Classifier using Transfer Learning

    Dog versus Cat has been a standard Problem in Machine Learning and Computer Vision that aims to build a model that can…

    3 条评论
  • Getting Started with NPM

    Getting Started with NPM

    Node.js is an Open-Source Server Environment that helps implements Javascript in Server-Side Operations and allows…

    5 条评论
  • Getting Started with ReactJS

    Getting Started with ReactJS

    The recent that has caught the attention of many Front-End Developers across the Javascript Ecosystem has been the word…

    7 条评论
  • Introduction to Natural Language Processing

    Introduction to Natural Language Processing

    Natural Language Processing or simply abbreviated as NLP is a highly specialized branch of Artificial Intelligence and…

    2 条评论
  • An Introduction to Neural Networks

    An Introduction to Neural Networks

    The renaissance of Artificial Intelligence with the boost in Machine Learning and Deep Learning terminologies has…

  • Blockchain and India

    Blockchain and India

    Blockchain is a new-age technology that has seen rapid strides in realization in our modern world and aims to bring…

社区洞察

其他会员也浏览了