VEERENDRA Internship Report 1
VEERENDRA Internship Report 1
Tech)
Jawaharlal Nehru Technological University Kakinada
University College of Engineering Kakinada (A)
Kakinada District, Andhra Pradesh – 533003
INTERNSHIP REPORT ON
V VEERENDRA(22021A409)
ABSTRACT
During our internship, we collaborated with a skilled team to develop and
implement machine learning models using Python, with a particular focus on
understanding and applying forward and backward propagation algorithms. Our
project aimed to build neural networks capable of performing complex predictive
tasks.
The National Institute of Technology Andhra Pradesh (NIT Andhra Pradesh) is one
of the premier engineering institutions in India, established as part of the NIT system to
provide high-quality technical education and promote research in various engineering
disciplines. Located in Tadepalligudem, West Godavari district, the institute was founded in
2015 and has quickly grown to become a center of excellence in engineering and technology.
The Institute places a strong emphasis on research and development, encouraging students
and faculty to engage in cutting-edge research projects. Collaborative research initiatives
with industry and other academic institutions are actively promoted.
The institute maintains strong ties with the industry through various collaborative projects,
internships, and placement programs. These partnerships provide students with valuable
exposure to real-world engineering challenges and opportunities for hands-on experience.
First, we would like to thank Dr Puli Kishore Kumar, Assistant Professor, Department of
Electronics and Communication Engineering, National Institute of Technology,
Tadepalligudem, Andhra Pradesh for giving us the opportunity to do an internship within
the Institution.
We also would like to thank all the people that worked along with us in the Institution with
their patience and openness they created an enjoyable learning and working environment.
We would like to thank our Head of the Department Dr B. Leela Kumari for her
constructive criticism throughout our internship.
We are extremely grateful to the department staff members and friends who helped us in
successful completion of this Internship.
V. VEERENDRA 22021A0409
ASHEESH NOEL 22021A0416
V.L.V. SHIVA CHARAN 23025A0459
K.V.S. NAGENDRA VARMA 23025A0461
INTRODUCTION TO MACHINE LEARNING
Machine learning is a subset of artificial intelligence (AI) that focuses on the development of
algorithms and statistical models that enable computers to perform tasks without explicit
instructions. Instead, machine learning systems learn from data, identifying patterns and making
decisions with minimal human intervention.
1. Supervised Learning:
In supervised learning, the algorithm is trained on a labelled dataset, which means that
each training example is paired with an output label. The goal is to learn a mapping from
inputs to outputs that can be used to predict the labels of new, unseen data. Common
tasks include classification and regression.
2. Unsupervised Learning:
Unsupervised learning involves training an algorithm on data without labelled responses.
The system tries to learn the underlying structure of the data. Common tasks include
clustering and dimensionality reduction.
3. Reinforcement Learning:
In reinforcement learning, an agent learns to make decisions by performing actions in an
environment to maximize cumulative rewards. This is often used in robotics, game
playing, and other applications where sequential decision-making is crucial.
4. Deep Learning:
A subset of machine learning, deep learning utilizes neural networks with many layers
(deep neural networks) to model complex patterns in large datasets. This approach has
led to breakthroughs in image recognition, natural language processing, and other areas.
Applications:
Machine learning is transforming industries by enabling more efficient and accurate decision-
making. Some notable applications include:
Software Used:
In our machine learning project, we utilized Google Colab, a cloud-based platform that provides
a powerful and flexible environment for developing and executing machine learning models.
Google Colab offers several benefits:
1. Accessibility: Google Colab is accessible from any device with internet access, allowing
for seamless collaboration and sharing of notebooks.
2. Integration with Popular Libraries: Google Colab supports a wide range of popular
Python libraries used in machine learning, including TensorFlow, Keras, PyTorch, scikit-
learn, and many others.
3. Ease of Use: The platform is user-friendly and supports Markdown, making it easy to
document and share code, explanations, and results in a single notebook.
NEURON
In machine learning, particularly in the realm of deep learning, neurons are the
fundamental building blocks of artificial neural networks (ANNs). Modelled loosely after the
biological neurons in the human brain, these artificial neurons are designed to process and
transmit information in a way that enables complex pattern recognition and decision-making
capabilities.
Biological Neuron:
Biological neurons are the basic units of the nervous system in living organisms, including
humans. The structure of a biological neuron consists of several components:
Cell Body: The cell body contains the nucleus and other organelles necessary for the
neuron's metabolic functions.
Myelin Sheath: The myelin sheath is a fatty, insulating layer that enhances the speed
and efficiency of nerve impulse transmission along axons.
Dendrites: Dendrites are branching extensions of the cell body that receive signals
from other neurons or sensory receptors.
Axon: The axon is a long, slender projection that conducts electrical impulses away
from the cell body and toward other neurons, muscles, or glands.
Synapses: Synapses are the junctions between neurons where electrochemical
communication occurs. Neurotransmitters released from the axon terminals of one
neuron transmit signals to the dendrites or cell body of another neuron.
Artificial Neuron:
Artificial neurons, also known as perceptron or nodes, are the building blocks of artificial
neural networks (ANNs) used in machine learning and deep learning. These neurons are
designed to mimic the basic functionality of biological neurons, albeit in a simplified and
mathematical form. The structure of an artificial neuron typically includes:
1. Architecture of MLP:
Input Layer: Receives input data, with each node representing a feature or attribute.
Hidden Layers: Intermediate layers between the input and output layers. Each hidden
layer contains one or more neurons, and the number of hidden layers and neurons can
vary depending on the complexity of the problem.
Output Layer: Produces the final output of the network, such as classification
probabilities or regression predictions. The number of nodes in the output layer
depends on the nature of the task.
2. Feedforward Process: The information flows in one direction, from the input layer
through the hidden layers to the output layer, without any cycles or loops. Each neuron
in a layer receives inputs from the neurons in the previous layer, performs a weighted
sum of these inputs, applies an activation function to the sum, and passes the result to the
neurons in the next layer.
3. Activation Functions: Nonlinear activation functions are applied to the weighted sum
of inputs in each neuron to introduce nonlinearity into the model and enable it to learn
complex patterns in the data. Common activation functions include sigmoid, tanh, ReLU
(Rectified Linear Unit), and softmax.
4. Training: MLPs are typically trained using the backpropagation algorithm, which
involves two main steps:
Forward Propagation: Compute the output of the network for a given input by
propagating the input through the layers.
Backpropagation: Compute the error between the predicted output and the true
output, and then propagate this error backward through the network to update the
weights using gradient descent optimization.
5. Applications:
MLPs are versatile and can be applied to a wide range of tasks, including:
Classification: Image classification, text classification, sentiment analysis.
Regression: Predictive modelling, time series forecasting.
Pattern Recognition: Handwritten digit recognition, speech recognition.
Reinforcement Learning: Building agents for game playing and robotics.
MLPs have been foundational in the development of deep learning and have paved the way
for more advanced architectures such as convolutional neural networks (CNNs) and recurrent
neural networks (RNNs). Despite their simplicity compared to these architectures, MLPs
remain powerful and effective for many machine learning tasks.
FORWARD PROPAGATION
Input Layer: The process begins with the input layer, where the raw input data is fed
into the network. Each input neuron represents a feature or attribute of the input data.
Weighted Sum: In each subsequent layer, the input from the previous layer is
multiplied by weights associated with the connections between neurons. These
weighted sums are then summed together, often with the addition of a bias term.
Activation Function: The weighted sum is passed through an activation function,
which introduces non-linearity into the network. Common activation functions
include sigmoid, ReLU, and tanh. This activation function determines whether a
neuron should be activated and to what extent.
Output Layer: The process continues through the hidden layers of the network until
the output layer is reached. The output layer produces the final predictions or outputs
of the network based on the activations of the neurons in the preceding layers.
Mathematical Expression:
Sigmoid Function: The sigmoid function maps the incoming inputs to a range
between 0 and 1.
Tanh Function: The Tanh function maps the incoming inputs to a range between -
1 and 1.
4. Final Expression:
Yi=(Wi*Xi) + Bi
Where i represent the layer in which the operation is being executed.
Program:
import numpy as np
r1,c1=map(int,input(‘Enter then number of rows and columns of w matrix: ‘).split())
print(‘Enter the elements of matrix: ‘)
w1=np.zeros((r1,c1))
for I in range(r1):
for j in range(c1):
w1[i][j]=input(‘Enter: ‘)
print(w1)
r3=r1
c3=1
print(‘Enter the elements of bias matrix: ‘)
b1=np.zeros((r3,c3))
for I in range(r3):
for j in range(c3):
b1[i][j]=input(‘Enter: ‘)
print(b1)
r2,c2=map(int,input(‘Enter then number of rows and columns of batches: ‘).split())
print(‘Enter the elements of batch: ‘)
x1=np.zeros((r2,c2))
for I in range(r2):
for j in range(c2):
x1[i][j]=input(‘Enter: ‘)
print(x1)
h1=np.dot(w1,x1)+b1
print(‘result: ‘)
print(h1)
ch=int(input(‘Select the Operation :\n1.ReLU Function\n2.Sigmoid Function(3-
Bit)\n3.Sigmoid Function(5-Bit)\n4.Tanh Function(3-Bit)\n5.Tanh Function(5-Bit)\n’))
if ch==1:
def relu(a):
return np.maximum(0,a) elif ch==4:
re_val=relu(h1) def tanh_f(x):
print(‘ReLU result: \n’) for I in range(0,len(x)):
print(re_val) if x[i]<=-2:
elif ch==2: print(‘-1’)
def sig(x): elif x[i]>=2:
for I in range(0,len(x)): print(‘1’)
if x[i]<=-2: else:
print(‘0’) print(‘0’)
elif x[i]>=2: print(‘TanH result:
print(‘1’) ‘) tanh_f(h1)
else: elif ch==5:
print(‘0.5’) def tanh_f(x):
print(‘Sigmoid result: ‘) for I in range(0,3):
sig(h1) if x[i]<=-2:
elif ch==3: print(‘-1’)
def sig(x): elif x[i]==-1:
for I in range(0,len(x)): print(‘-0.8’)
if x[i]<=-2: elif x[i]==0:
print(‘0’) print(‘0’)
elif x[i]==-1: elif x[i]==1:
print(‘0.3’) print(‘0.8’)
elif x[i]==0: else:
print(‘0.5’) print(‘1’)
elif x[i]==1: print(‘TanH result:
print(‘0.7’) ‘) tanh_f(h1)
else: else:
print(‘1’) print(‘Invalid Choice.’)
print(‘Sigmoid result: ‘)
sig(h1)
Output:
Enter then number of rows and columns of w matrix: 3 2
Enter the elements of matrix:
Enter: 1
Enter: 1
Enter: 1
Enter: 1
Enter: 1
Enter: 1
[[1. 1.]
[1. 1.]
[1. 1.]]
Enter the elements of bias matrix:
Enter: -2
Enter: -4
Enter: -6
[[-2.]
[-4.]
[-6.]]
Enter then number of rows and columns of batches: 2 1
Enter the elements of batch:
Enter: 3
Enter: 2
[[3.]
[2.]]
result:
[[ 3.]
[ 1.]
[-1.]]
Select the Operation:
1. ReLU Function
2. Sigmoid Function(3-Bit)
3. Sigmoid Function(5-Bit)
4. Tanh Function(3-Bit)
5. Tanh Function(5-Bit)
1
ReLU result:
[[3.]
[1.]
[0.]]
BACK PROPAGATION
Loss: The loss, or error, is computed by comparing the predicted output to the
actual target values using a loss function (e.g., mean squared error, cross-entropy
loss).
Backward Propagation: The gradients of the loss function with respect to the
weights and biases are computed using the chain rule of calculus. This involves
propagating the error backward through the network from the output layer to the
input layer.
Advantages:
Scalability: Backpropagation scales well with the size of the dataset and the
complexity of the network. This scalability makes it suitable for large-scale
machine learning tasks.
Mathematical Expression:
New Weight: This is an optimization technique which used to find the minimum
value of the function.
SoftMax Function: The softmax activation function forces the values of the
output neurons to take values between zero and one, so that they can represent
probability values in the interval [0, 1].
Gradient:
The Weights of the input are kept at random values with respect to the input
values so that the input layer.
The Hidden layer operation is implemented and the cost function is determined
from the Target output using the Obtained output.
Also, the learning rate of the system can also be determined by using the alpha or
constant to the required value.
Then, this cost function is added to the weights to modify them to get the target
output from the output layer when the loss will be very low or negligible.
Program:
import numpy as np
# X = (hours sleeping, hours studying), y = test score of the student
X = np.array(([2, 9], [1, 5], [3, 6]), dtype=float)
y = np.array(([92], [86], [89]), dtype=float)
# scale units
X = X/np.amax(X, axis=0) #maximum of X array
y = y/100 # maximum test score is 100
print(X)
class NeuralNetwork(object):
def init (self):
#parameters
self.inputSize = 2
self.outputSize = 1
self.hiddenSize = 3
#weights
self.W1 = np.random.randn(self.inputSize, self.hiddenSize) # (3x2) weight matrix from
input to hidden layer
self.W2 = np.random.randn(self.hiddenSize, self.outputSize) # (3x1) weight matrix
from hidden to output layer
def 21robabiliti(self, X):
#forward propogation through the network
self.z = np.dot(X, self.W1) #dot product of X (input) and first set of weights (3x2)
self.z2 = self.sigmoid(self.z) #activation function
self.z3 = np.dot(self.z2, self.W2) #dot product of hidden layer (z2) and second set of
weights (3x1)
output = self.sigmoid(self.z3)
return output
print(output)
def sigmoid(self, s, deriv=False):
if (deriv == True):
return s * (1 – s)
return 1/(1 + np.exp(-s))
def backward(self, X, y, output):
#backward propogate through the network
self.output_error = y – output # error in output
self.output_delta = self.output_error * self.sigmoid(output, deriv=True)
self.z2_error = self.output_delta.dot(self.W2.T) #z2 error: how much our hidden layer
weights contribute to output error
self.z2_delta = self.z2_error * self.sigmoid(self.z2, deriv=True) #applying derivative of
sigmoid to z2 error
self.W1 += X.T.dot(self.z2_delta) # adjusting first set (input -> hidden) weights
self.W2 += self.z2.T.dot(self.output_delta) # adjusting second set (hidden -> output)
weights
def train(self, X, y):
output = self.feedForward(X)
self.backward(X, y, output)
NN = NeuralNetwork()
Output:
[[0.66666667 1. ]
[0.33333333 0.55555556]
[1. 0.66666667]]
Loss: 0.009334108908074934
Loss: 0.0010916905194009302
Loss: 0.0010296010947815793
Loss: 0.0009833495674670032
Loss: 0.0009399137312401804
Loss: 0.0008989599161029326
Loss: 0.000860280141810026
Loss: 0.0008236997891859802
Loss: 0.0007890698311634454
Loss: 0.0007562613646175108
Input:
[[0.66666667 1. ]
[0.33333333 0.55555556]
[1. 0.66666667]]
Actual Output:
[[0.92]
[0.86]
[0.89]]
Loss: 0.0007251613933311722
Predicted Output:
[[0.88519048]
[0.88927613]
[0.90032907]]
Applications:
One of the main applications of Back Propagation is that the machine can learn to
implement the given code and learn the operation based on the given conditions.
This is used to identify the given number which is in the form of Handwritten
digits to get the accurate number.
Handwritten digit recognition using Python machine learning involves the
development of algorithms that can accurately identify handwritten digits from
images.
This task is widely recognized as a fundamental problem in the field of computer
vision and has numerous real-world applications, including optical character
recognition (OCR), automatic form processing, and postal sorting.
The process typically involves several key steps:
6. Model Deployment: Once the model has been trained and evaluated, it can be
deployed into production environments where it can be used to recognize
handwritten digits in real-time applications.
MNIST DATASET:
The MNIST dataset is a widely used benchmark dataset in the field of machine
learning and computer vision. It consists of a large collection of grayscale images of
handwritten digits, each labelled with the corresponding digit (0 through 9). The MNIST
dataset is commonly used for training and testing machine learning algorithms, particularly
for tasks such as digit recognition.
Here are some key characteristics of the MNIST dataset:
Size: The dataset contains 70,000 images in total, divided into 60,000 training
images and 10,000 test images.
Labelling: Each image is associated with a label indicating the digit it represents.
The labels range from 0 to 9, corresponding to the digits 0 through 9.
To import the MNIST dataset into your Python environment, you can use popular
machine learning libraries such as TensorFlow or scikit-learn, which provide convenient
functions for downloading and loading the dataset:
import tensorflow as tf
Program:
import tensorflow as tf
import matplotlib.pyplot as plt
import seaborn as sn
import numpy as np
import pandas as pd
import math
import datetime
import platform
# Input layers.
Model.add(tf.keras.layers.Flatten(input_shape=x_train_normalized.shape[1:]))
model.add(tf.keras.layers.Dense(
units=128,
activation=tf.keras.activations.relu,
kernel_regularizer=tf.keras.regularizers.l2(0.002)
))
# Hidden layers.
Model.add(tf.keras.layers.Dense(
units=128,
activation=tf.keras.activations.relu,
kernel_regularizer=tf.keras.regularizers.l2(0.002)
))
# Output layers.
Model.add(tf.keras.layers.Dense(
units=10,
activation=tf.keras.activations.softmax
))
tf.keras.utils.plot_model( mo
del, show_shapes=True,
show_layer_names=True,
)
adam_optimizer = tf.keras.optimizers.Adam(learning_rate=0.001)
model.compile( optimizer=adam_opt
imizer,
loss=tf.keras.losses.sparse_categorical_crossentropy,
metrics=[‘accuracy’]
)
log_dir=”.logs/fit/” + datetime.datetime.now().strftime(“%Y%m%d-%H%M%S”)
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
training_history = model.fit(
x_train_normalized,
y_train,
epochs=10,
validation_data=(x_test_normalized, y_test),
callbacks=[tensorboard_callback]
)
plt.xlabel(‘Epoch Number’)
plt.ylabel(‘Loss’)
plt.plot(training_history.history[‘loss’], label=’training set’)
plt.plot(training_history.history[‘val_loss’], label=’test set’)
plt.legend()
plt.xlabel(‘Epoch Number’)
plt.ylabel(‘Accuracy’)
plt.plot(training_history.history[‘accuracy’], label=’training set’)
plt.plot(training_history.history[‘val_accuracy’], label=’test set’)
plt.legend()
##capture
train_loss, train_accuracy = model.evaluate(x_train_normalized, y_train)
print(‘Training loss: ‘, train_loss)
print(‘Training accuracy: ‘, train_accuracy)
##capture
validation_loss, validation_accuracy = model.evaluate(x_test_normalized, y_test)
print(‘Validation loss: ‘, validation_loss)
print(‘Validation accuracy: ‘, validation_accuracy)
model_name = ‘Back Propagation.h5’
model.save(model_name, save_format=’h5’)
loaded_model = tf.keras.models.load_model(model_name)
predictions_one_hot = loaded_model.predict([x_test_normalized])
print(‘predictions_one_hot:’, predictions_one_hot.shape)
# Predictions in form of one-hot vectors (arrays of probabilities).
Pd.DataFrame(predictions_one_hot)
# Let’s extract predictions with highest 29robabilities and detect what digits have been
actually recognized.
Predictions = np.argmax(predictions_one_hot, axis=1)
pd.DataFrame(predictions)
print(predictions[0])
plt.imshow(x_test_normalized[0], cmap=plt.cm.binary)
plt.show()
numbers_to_display = 196
num_cells = math.ceil(math.sqrt(numbers_to_display))
plt.figure(figsize=(15, 15))
plt.subplots_adjust(hspace=1, wspace=0.5)
plt.show()
Output:
Python version: 3.10.12
Tensorflow version: 2.15.0
x_train: (60000, 28, 28)
y_train: (60000,)
x_test: (10000, 28, 28)
y_test: (10000,)
28 rows × 28 columns
Epoch 1/10
1875/1875 [==============================] – 12s 6ms/step – loss: 0.5130 –
accuracy: 0.9234 – val_loss: 0.3519 – val_accuracy: 0.9440
Epoch 2/10
1875/1875 [==============================] – 9s 5ms/step – loss: 0.3007 –
accuracy: 0.9549 – val_loss: 0.2929 – val_accuracy: 0.9533
Epoch 3/10
1875/1875 [==============================] – 11s 6ms/step – loss: 0.2605 –
accuracy: 0.9608 – val_loss: 0.2410 – val_accuracy: 0.9638
Epoch 4/10
1875/1875 [==============================] – 11s 6ms/step – loss: 0.2387 –
accuracy: 0.9637 – val_loss: 0.2252 – val_accuracy: 0.9659
Epoch 5/10
1875/1875 [==============================] – 11s 6ms/step – loss: 0.2238 –
accuracy: 0.9651 – val_loss: 0.2174 – val_accuracy: 0.9652
Epoch 6/10
1875/1875 [==============================] – 10s 5ms/step – loss: 0.2143 –
accuracy: 0.9671 – val_loss: 0.2042 – val_accuracy: 0.9684
Epoch 7/10
1875/1875 [==============================] – 14s 7ms/step – loss: 0.2062 –
accuracy: 0.9678 – val_loss: 0.1972 – val_accuracy: 0.9709
Epoch 8/10
1875/1875 [==============================] – 12s 6ms/step – loss: 0.2014 –
accuracy: 0.9674 – val_loss: 0.2012 – val_accuracy: 0.9673
Epoch 9/10
1875/1875 [==============================] – 18s 10ms/step – loss: 0.1963 –
accuracy: 0.9688 – val_loss: 0.1949 – val_accuracy: 0.9688
Epoch 10/10
1875/1875 [==============================] – 10s 5ms/step – loss: 0.1927 –
accuracy: 0.9691 – val_loss: 0.2001 – val_accuracy: 0.9673
1875/1875 [==============================] – 4s 2ms/step – loss: 0.1875 –
accuracy: 0.9714
Training loss: 0.18751470744609833
Training accuracy: 0.9714000225067139
313/313 [==============================] – 1s 3ms/step – loss: 0.2001 – accuracy:
0.9673
Validation loss: 0.20008863508701324
Validation accuracy: 0.9672999978065491
PROGRAMMING USING PYNQ BOARD
PYNQ (Python Productivity for Zynq) is an open-source project from Xilinx that aims to
make it easier to program FPGA-based systems using Python. PYNQ is a platform that
allows you to harness the power of FPGAs using the simplicity and flexibility of Python,
making it easier for developers and researchers to create high-performance applications.
PYNQ-Z2 board
Micro USB cable
Ethernet cable
SD card
Computer with an Internet connection
Insert the SD card into the SD card slot on the PYNQ-Z2 board.
2. Connect the PYNQ-Z2 Board to Your
Computer Power the Board:
Connect one end of the Ethernet cable to the Ethernet port on the
PYNQ-Z2 board.
Connect the other end of the Ethernet cable to your router or switch.
Access the PYNQ-Z2 Board:
The PYNQ-Z2 board will boot from the SD card. Wait a few moments
for the board to initialize.
Access your router’s web interface and check the list of connected
devices. Look for the PYNQ-Z2 board and note its IP address.
Using USB Connection:
Enter the IP address of the PYNQ-Z2 board into the browser's address
bar, followed by :9090. For example, if the IP address is 192.168.1.99,
enter http://192.168.1.99:9090.
Log In:
The Jupyter Notebook login page will appear. The default password is
“xilinx”.
Troubleshooting:
1. No Power: Ensure the micro-USB cable is securely connected to both the PYNQ-Z2
board and the power source.
2. No Network Connection: Check that the Ethernet cable is properly connected and
your router is configured to assign IP addresses via DHCP.
Leveraging Python's rich ecosystem of libraries such as TensorFlow and scikit-learn, the
convergence of machine learning and embedded systems holds immense promise for
revolutionizing industries ranging from healthcare and finance to robotics and IoT. By
embracing the versatility of Python and the computational prowess of the PYNQ board, we
are eager to unlock new frontiers in intelligent systems, driving innovation and shaping the
digital landscape for generations to come.