More GameFi Projects

While hardcore fans love to watch their favorite athletes fight side by side for the world cup, they seemingly crave for the ability to control the decisions and movements of athletes through…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Basics of TensorFlow 2.0 and Training a Model

TensorFlow is a numerical processing library was originally developed at Google used by researchers and machine learning practitioners to conduct machine learning research. You can perform any numerical operation with TensorFlow, it is mostly used to train and run deep neural networks.

TensorFlow primarily offers to simplify the deployment of machine learning and deep learning solutions on various platforms — computer CPUs,GPUs, mobile devices, and, more recently, in the browser. On top of that, TensorFlow offers many useful functions for creating machine learning models and running them at scale. In 2019, TensorFlow 2 was released with a focus on ease of use while maintaining good performance.

TensorFlow 2.0 allowing newcomers to start with a simple API and experts to create very complex models at the same time. Let’s explore those different levels.

TensorFlow 2 architecture has several levels of abstraction. Let’s first introduce the lowest layer and find our way to the uppermost layer:

Explaining the layers of architecture:

C++ Layer

Most deep learning computations are coded in C++. To run operations on the GPU, TensorFlow uses a library developed by NVIDIA called CUDA.This is the reason you need to install CUDA if you want to exploit GPU capabilities and why you cannot use GPUs from another hardware manufacturer.

Low-level API

The Python low-level API then wraps the C++ sources. When you call a Python method in TensorFlow, it usually invokes C++ code behind the scenes. This wrapper layer allows users to work more fast because Python is considered easier to use than C++ and does not require compilation. This Python wrapper makes it possible to perform extremely basic operations such as matrix multiplication and addition.

High-level API

At the top sits the high-level API, made of two components — Keras and the Estimator API. Keras is a user-friendly, modular, and extensible wrapper for TensorFlow. The Estimator API contains several pre-made components that allow you to build your machine learning model easily. You can consider them building blocks or templates. pre-made components let you experiment with different model architectures by making only minimal code changes.

Keras was first released in 2015 and designed as an interface to enable fast experimentation with neural networks. There are several deep learning frameworks out there that helps for building deep neural networks. TensorFlow, Theano, CNTK (Microsoft) are some of the major frameworks used in the industry and in the research. Keras act as a wrapper for these frameworks. Known for its user-friendliness, it is the library of choice and ultimate deep learning tool for developers.

Architecture of Keras API

Basically, Keras models go through the following pipeline.

Let’s start with a classical example of computer vision — digit recognition with the Modified National Institute of Standards and Technology (MNIST) datasets.

For installation of TensorFlow 2.x version.

First, we import the data. It is made up of 60,000 images for the training set and 10,000 images for the test set:

Moving to building the actual model. We will use a very simple architecture composed of two fully connected layers called as Dense layers . Now, let’s have a look at the code. As you can see, Keras code is very briefly and clearly written.

Since our model is a linear stack of layers, we start by calling the Sequential function. We then add each layer one after the other. Our model is composed of two fully connected layers. We build it layer by layer:

You can get a description of the model, the outputs, and their weights.

Here is the output:

Keras makes training extremely simple:

Calling .compile() on the model we just created is a mandatory step. A few arguments must be specified:

Then, we call the .fit() method. We will train for five epochs, meaning that we will iterate over the whole train dataset five times. Notice that we set verbose to 1. This will allow us to get a progress bar with the metrics we chose earlier, the loss, and the Estimated Time of Arrival (ETA). The ETA is an estimate of the remaining time before the end of the epoch. Here is what the progress bar looks like:

Evaluate the model:

We followed three main steps:

The whole process was extremely simple thanks to Keras, the high-level API of TensorFlow. Behind this simple API, the library hides a lot of the complexity.

REFERENCES:

Add a comment

Related posts:

Giorno 7

Ero in questo locale con amici di amici, che però anche gli amici degli amici degli amici mi stavano sul cazzo. La playlist è tipo incentrata su Baby-K (che poi mi piacerebbe aprire una parentesi su…

Bezant Blockchain For A Better World

A decentralized loaning environment that encourages open access to credit anyplace and whenever in light of the Ethereum blockchain. • Consists of 20+ full-time designers: including 10 engineers who…

Use of Assistive Technology to Address the Overwhelming Sensory Stimuli in Individuals with Autism Spectrum Disorder

The use of assistive technology as a tool for individuals with autism spectrum disorder has greatly increased over the past decade. Individuals with autism experience difficulties in sensory…