ML Unit-5
ML Unit-5
Neural Networks and Deep Learning: Introduction to Artificial Neural Networks with
Keras, Implementing MLPs with Keras, Installing TensorFlow 2, Loading and Preprocessing
Data with TensorFlow
Artificial Neural Network Tutorial provides basic and advanced concepts of ANNs. Our
Artificial Neural Network tutorial is developed for beginners as well as professions.
The term "Artificial neural network" refers to a biologically inspired sub-field of artificial
intelligence modeled after the brain. An Artificial neural network is usually a computational
network based on biological neural networks that construct the structure of the human brain.
Similar to a human brain has neurons interconnected to each other, artificial neural networks
also have neurons that are linked to each other in various layers of the networks. These neurons
are known as nodes.
Artificial neural network tutorial covers all the aspects related to the artificial neural network.
In this tutorial, we will discuss ANNs, Adaptive resonance theory, Kohonen self-organizing
map, Building blocks, unsupervised learning, Genetic algorithm, etc.
The term "Artificial Neural Network" is derived from Biological neural networks that
develop the structure of a human brain. Similar to the human brain that has neurons
interconnected to one another, artificial neural networks also have neurons that are
interconnected to one another in various layers of the networks. These neurons are known as
nodes.
The given figure illustrates the typical diagram of Biological Neural Network.
The typical Artificial Neural Network looks something like the given figure.
Dendrites from Biological Neural Network represent inputs in Artificial Neural Networks, cell
nucleus represents Nodes, synapse represents Weights, and Axon represents Output.
Dendrites Inputs
Synapse Weights
Axon Output
An Artificial Neural Network in the field of Artificial intelligence where it attempts to
mimic the network of neurons makes up a human brain so that computers will have an option
to understand things and make decisions in a human-like manner. The artificial neural network
is designed by programming computers to behave simply like interconnected brain cells.
There are around 1000 billion neurons in the human brain. Each neuron has an association
point somewhere in the range of 1,000 and 100,000. In the human brain, data is stored in such
a manner as to be distributed, and we can extract more than one piece of this data when
necessary from our memory parallelly. We can say that the human brain is made up of
incredibly amazing parallel processors.
We can understand the artificial neural network with an example, consider an example of a
digital logic gate that takes an input and gives an output. "OR" gate, which takes two inputs. If
one or both the inputs are "On," then we get "On" in output. If both the inputs are "Off," then
we get "Off" in output. Here the output depends upon input. Our brain does not perform the
same task. The outputs to inputs relationship keep changing because of the neurons in our brain,
which are "learning."
Multi-Layer perceptron defines the most complex architecture of artificial neural networks. It
is substantially formed from multiple layers of the perceptron. TensorFlow is a very popular
deep learning framework released by, and this notebook will guide to build a neural network
with this library. If we want to understand what is a Multi-layer perceptron, we have to develop
a multi-layer perceptron from scratch using Numpy.
MLP networks are used for supervised learning format. A typical learning algorithm for MLP
networks is also called back propagation's algorithm.
A multilayer perceptron (MLP) is a feed forward artificial neural network that generates a set
of outputs from a set of inputs. An MLP is characterized by several layers of input nodes
connected as a directed graph between the input nodes connected as a directed graph between
the input and output layers. MLP uses backpropagation for training the network. MLP is a deep
learning method.
Now, we are focusing on the implementation with MLP for an image classification problem.
import tensorflow as tf
import matplotlib.pyplot as plt
# Parameters
learning_rate = 0.001
training_epochs = 20
batch_size = 100
display_step = 1
# Network Parameters
n_hidden_1 = 256
# weights layer 2
w = tf.Variable(tf.random_normal([n_hidden_1, n_hidden_2]))
# cost function
cost = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
logits = output_layer, labels = y))
# optimizer = tf.train.GradientDescentOptimizer(
learning_rate = learning_rate).minimize(cost)
# Plot settings
avg_set = []
epoch_set = []
# Test model
correct_prediction = tf.equal(tf.argmax(output_layer, 1), tf.argmax(y, 1))
# Calculate accuracy
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
print
"Model Accuracy:", accuracy.eval({x: mnist.test.images, y: mnist.test.labels})
We have two basic options when using TensorFlow to run our code:
o Build graphs and run sessions [Do all the set-up and then execute a session to implement
a session to evaluate tensors and run operations].
o Create our coding and run on the fly.
For this first part, we will use the interactive session that is more suitable for an environment
like Jupiter notebook.
sess = tf.InteractiveSession()
In this tutorial, we will describe that how to install TensorFlow in Windows 10.
1. Through pip
So, firstly we have to install and set-up anaconda in our system through pip.
The following are the requirement for TensorFlow to work on our computer.
64.2M
1.3K
Next
Stay
o TensorFlow has only supported 64-bit Python 3.5.x or Python 3.6.x on Windows
o When we download the Python 3.5.x version, it comes with the pip3 package manager.
(Which is the program that we are going to need for our users to install TensorFlow on
Windows).
https://w
ww.python.org/downloads/release/python-352/
After that,
Step 3: We will be brought to another page, where we will need to select either the x86-
64 or amd64 installer to install Python.
Now, Python is installing successfully.
Step 4: For this tutorial, I'll be choosing to Add Python 3.5 to PATH.
Step 5: Now, we will be able to see the message "Set-up was successful." A way to confirm
that it hs installed successfully is to open your Command Prompt and check the version.
What is pip?
pip is known as a package management system which is used to install and manage the
software package, which is written in Python or any other languages. pip is used to download,
search, install, uninstall, and manage the 3rd party python package. (pip3 is the latest version
of it which comes with new Python 3.5.x version that we had just downloaded)
Once we have downloaded the latest version of Python, we can now put our finishing touches
by installing our TensorFlow.
Step 1: To install TensorFlow, start the terminal. Make sure that we run the cmd as an
administrator.
Open the Start menu, search for cmd, and then right-click on it and Run as an administrator.
Open the Start menu, search for cmd, and then right-click on it and Run as an administrator.
Step 2: Once we are done with that, then we have to write the command in command
prompt for finish installing Tensorflow in our Windows.
Otherwise, If we are getting any problem to run the program, then we have to
install Microsoft Visual C++ 2015. And set up in our system then the TensorFlow will be
run in the system.
For any small CSV dataset the simplest way to train a TensorFlow model on it is
to load it into memory as a pandas Dataframe or a NumPy array. A relatively
simple example is the abalone dataset. The dataset is small. All the input features
are all limited-range floating point values.